【发布时间】:2023-01-04 20:02:59
【问题描述】:
我在 PKCE 中使用授权码授予。我试图通过 api 毫无问题地撤销令牌(路由在 auth:api 中间件下)。但是,服务器端会话尚未结束,当我尝试再次登录时,它会跳过登录表单并跳转到授权提示或只是回调页面。我试图在 Web 中间件中创建一个路由,该路由会终止会话,但始终存储 cookie“laravel_session”和“XSRF-TOKEN”并且无法删除它们。
我想让用户从移动应用程序中单击注销按钮,并且用户在再次登录时应完成整个 oauth2 流程,而不是跳过服务器端的登录表单。
public function logoutAPI(){
//clear server side session
Auth::guard('web')->logout();
Session::flush();
// logout and revoke mobile app token
Auth::user()->token()->revoke();
$tokenId = Auth::user()->token()->id;
$tokenRepository = app('Laravel\Passport\TokenRepository');
$refreshTokenRepository = app('Laravel\Passport\RefreshTokenRepository');
$tokenRepository->revokeAccessToken($tokenId);
$refreshTokenRepository->revokeRefreshTokensByAccessTokenId($tokenId);
return response()->json([
'msg' => 'You have been succesfully logged out'
],200);
请注意,我不会在这里使用其他授权类型作为参考https://oauth2.thephpleague.com/authorization-server/which-grant/
【问题讨论】:
-
登录时您如何执行身份验证?我建议你使用 Auth:once
-
@AqibJaved 我使用默认
auth()->attempt'. I did tried 1Auth:once. However, the urloauth/authorize` 是默认使用会话。意味着如果使用Auth:once,我将在没有会话的情况下继续在登录页面循环。
标签: php laravel laravel-8 laravel-passport