本文整理汇总了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);
});
}
示例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();
}
});
}
示例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);
});
}
示例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();
}
});
}
示例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;
}
});
}
示例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;
});
}