當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。