【问题标题】:Laravel Passport authentication via cookie - expire on logout?通过 cookie 进行 Laravel Passport 身份验证 - 注销时过期?
【发布时间】:2023-03-15 09:46:01
【问题描述】:

在我的项目中,我正在集成 Laravel Passport,以便在我的应用程序中使用我的 API,如 here 所述。

我的问题是关于 laravel_token cookie 的到期时间。可以看到here,我的应用程序发回的cookie被检查以验证它没有过期。这个过期时间似乎是由我的会话生命周期定义的 - 请参阅 here

这似乎意味着 laravel_token cookie 即使在我的应用程序的用户注销后仍然有效,只要会话时间没有过期(事实上,如果我删除所有会话似乎是这样的服务器并注销我的用户,使用 cookie 的 API 请求仍然成功)。

这是预期的行为吗?如果用户注销,是否有办法自动使 cookie 过期? (我知道 cookie 已从用户系统中删除,但我是从理论上 cookie 被劫持或被盗的可能性来看的,然后只要会话生命周期未过期就可以使用)。

【问题讨论】:

  • 这并不能回答你的问题,但是 Laravel 默认使用安全的 HttpOnly cookie,并且在使用所描述的身份验证机制时需要额外的 CSRF 令牌。最后,这种方法使会话被成功劫持的可能性相当低,我认为这是安全的。
  • @Radical 嘿,你有没有找到任何方法在注销时“过期”令牌?

标签: laravel laravel-5 laravel-passport


【解决方案1】:

试试这个方法,在这种情况下,refresh_tokens 被禁用,cookies 也会丢失。

    $accessToken = Auth::user()->token();
    DB::table('oauth_refresh_tokens')
        ->where('access_token_id', $accessToken->id)
        ->update(['revoked' => true]);
    $accessToken->revoke();

    \Cookie::queue(\Cookie::forget(Passport::cookie()));

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 1970-01-01
    • 2018-07-20
    • 2012-01-30
    • 2019-06-05
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多