阅读(4103) (7)

Laravel 8 多个身份验证 guard

2021-07-09 12:59:44 更新

如果您的应用程序可能使用完全不同的 Eloquent 模型、不同类型的用户进行身份验证,则可能需要为应用程序中的每种用户设置 guard。 这使您可以保护特定 guard 的请求。 例如,设置以下 guard config/auth.php 配置文件:

'api' => [
    'driver' => 'passport',
    'provider' => 'users',
],

'api-customers' => [
    'driver' => 'passport',
    'provider' => 'customers',
], 

以下路由将使用 customers 用户提供者的 api-customers guard 来验证传入的请求:

Route::get('/customer', function () {
    //
})->middleware('auth:api-customers'); 

技巧:有关在 Passport 上使用多个用户提供者的更多信息,请查阅密码授予文档.