小编Ric*_*lho的帖子

Laravel - 如何获得认证用户的警卫?

我有一个定制的LoginController有两个函数:

loginCustomer运行Auth :: guard('customer') - > attempt(...);

loginEmployee运行Auth :: guard('employee') - > attempt(...);

我在config.auth中定制了两个警卫,指向我的两个模型(客户和员工)并保护后台和前端的路由.

现在在我的自定义LogoutController中我想运行Auth :: logout()但它不起作用,因为我认为它使用默认的后卫.

它只有在我指定Auth::guard('customer')->logout()Auth::guard('employee')->logout()取决于用于登录的防护时才有效.

有没有办法让防护用于验证用户,所以我只能使用Auth::guard($guard)->logout

laravel

5
推荐指数
2
解决办法
6874
查看次数

是否可以避免数据库中的大量访问令牌?

我已经使用Laravel Passport项目构建了RESTful API。
它使用“客户证书授予”来授权我的第三方项目。
问题在于,对于来自第三方应用程序的每个api调用,它都会生成一个新的访问令牌。
到一天结束时,如果我有999个电话,我在oauth_access_tokens数据库表中还将有999条新记录。
是否有可能避免数据库中的大量访问令牌?

也许在League \ OAuth2 \ Server \ Grant \ ClientCredentialsGrant.php中:

public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, \DateInterval $accessTokenTTL) {
    $client = $this->validateClient($request);
    $scopes = $this->validateScopes($this->getRequestParameter('scope', $request));
    $scopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client);
    // $validToken = query to check if $client has existing token neither revoked or expired
    // if ($validToken) { 
    //     return $responseType->setAccessToken($validToken);
    // }
    $accessToken = $this->issueAccessToken($accessTokenTTL, $client, null, $scopes);
    $responseType->setAccessToken($accessToken);
    return $responseType;
}
Run Code Online (Sandbox Code Playgroud)

laravel laravel-passport

3
推荐指数
1
解决办法
1147
查看次数

标签 统计

laravel ×2

laravel-passport ×1