当前位置: 首页>>代码示例>>PHP>>正文


PHP Auth::viaRequest方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Auth::viaRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::viaRequest方法的具体用法?PHP Auth::viaRequest怎么用?PHP Auth::viaRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Auth的用法示例。


在下文中一共展示了Auth::viaRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 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);
     });
 }
开发者ID:KodiComponents,项目名称:module-api,代码行数:7,代码来源:ModuleServiceProvider.php

示例2: boot

 /**
  * 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();
         }
     });
 }
开发者ID:edcoreweb,项目名称:dominox,代码行数:13,代码来源:AuthServiceProvider.php

示例3: boot

 /**
  * 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);
     });
 }
开发者ID:defenestrator,项目名称:groid,代码行数:16,代码来源:SparkServiceProvider.php

示例4: boot

 /**
  * 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();
         }
     });
 }
开发者ID:hanson,项目名称:wechat,代码行数:17,代码来源:AuthServiceProvider.php

示例5: boot

 /**
  * 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;
         }
     });
 }
开发者ID:amteknologi,项目名称:e-commerce,代码行数:20,代码来源:AuthServiceProvider.php

示例6: boot

 /**
  * 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;
     });
 }
开发者ID:teladan48,项目名称:restful-server,代码行数:53,代码来源:AuthServiceProvider.php


注:本文中的Illuminate\Support\Facades\Auth::viaRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。