public function boot(Router $router)
 {
     $router->middlewareGroup('api', [\KodiCMS\API\Http\Middleware\VerifyApiToken::class]);
     Auth::viaRequest('token', function ($request) {
         return app(TokenGuard::class)->user($request);
     });
 }
Пример #2
0
 /**
  * Boot the authentication services for the application.
  *
  * @return void
  */
 public function boot()
 {
     Auth::viaRequest('api', function ($request) {
         if ($token = $request->input('api_token')) {
             return User::where('api_token', $token)->first();
         }
     });
 }
Пример #3
0
 /**
  * Boot the service provider.
  *
  * @return void
  */
 public function boot()
 {
     $this->defineRoutes();
     $this->defineResources();
     Validator::extend('state', StateValidator::class . '@validate');
     Validator::extend('country', CountryValidator::class . '@validate');
     Validator::extend('vat_id', VatIdValidator::class . '@validate');
     Auth::viaRequest('spark', function ($request) {
         return app(TokenGuard::class)->user($request);
     });
 }
Пример #4
0
 /**
  * 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.
     Auth::viaRequest('api', function ($request) {
         if ($request->input('api_token')) {
             return User::where('api_token', $request->input('api_token'))->first();
         }
     });
 }
 /**
  * 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.
     Auth::viaRequest('api', function ($request) {
         try {
             $playload = JWTAuth::parseToken()->getPayload();
             return User::find($playload['sub']);
         } catch (JWTException $e) {
             return null;
         }
     });
 }
 /**
  * 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.
     Auth::viaRequest('api', function (Request $request) {
         $authorization_header = explode(' ', $request->header('Authorization'));
         if (count($authorization_header) != 2 || strpos($authorization_header[0], 'Bearer')) {
             throw new Exception('Authorization header not set or invalid.');
         }
         $user = User::where('api_token', $authorization_header[1])->first();
         if (is_null($user)) {
             throw new Exception('Invalid access token.');
         }
         return $user;
     });
     // Event Authorization
     Gate::define('create-event', function (User $user) {
         return $user->hasPermission('create-event');
     });
     Gate::define('update-event', function (User $user, Event $event) {
         return $user->hasPermission('update-event') && $user->id === $event->user_id;
     });
     Gate::define('delete-event', function (User $user, Event $event) {
         return $user->hasPermission('delete-event') && $user->id === $event->user_id;
     });
     Gate::define('view-event', function (User $user, Event $event) {
         return $user->hasPermission('view-event');
     });
     Gate::define('list-event', function (User $user) {
         return $user->hasPermission('list-event');
     });
     // User Authorization
     Gate::define('list-user', function (User $user) {
         return $user->hasPermission('list-user');
     });
     Gate::define('view-user', function (User $user, User $user_check) {
         return $user->hasPermission('view-user');
     });
     // User Location Authorization
     Gate::define('list-user-location', function (User $user) {
         return $user->hasPermission('list-user-location');
     });
     Gate::define('update-user-location', function (User $user, User $user_check) {
         return $user->hasPermission('update-user-location') && $user->id === $user_check->id;
     });
 }