2018-04-09 21:38:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use App\User;
|
2018-04-26 23:02:06 +02:00
|
|
|
use Illuminate\Http\Request;
|
2018-04-09 21:38:31 +02:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot the authentication services for the application.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
// Here you may define how you wish users to be authenticated for your Lumen
|
|
|
|
// application. The callback which receives the incoming request instance
|
|
|
|
// should return either a User instance or null. You're free to obtain
|
|
|
|
// the User instance via an API token or any other method necessary.
|
|
|
|
|
2018-04-26 23:02:06 +02:00
|
|
|
$this->app['auth']->viaRequest('api', function ( Request $request) {
|
2018-04-29 22:43:29 +02:00
|
|
|
if ($request->input('token')) {
|
2018-04-26 23:02:06 +02:00
|
|
|
return User::where('token', $request->input('token'))
|
2018-04-29 22:43:29 +02:00
|
|
|
// ->where('email', $request->input('email'))
|
2018-04-26 23:02:06 +02:00
|
|
|
->first();
|
2018-04-09 21:38:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|