【问题标题】:Laravel passport: createToken with time lifeLaravel 护照:createToken with time life
【发布时间】:2018-07-27 17:56:30
【问题描述】:

即使我在服务提供商中有 Passport::tokensExpireIn($time),当我创建用户令牌时:

$user->createToken('Token');

我认为寿命大约为 1 年?如何在不使用 DB::table 的情况下更改生命周期?

【问题讨论】:

    标签: laravel time token


    【解决方案1】:

    根据 Laravel 文档,您将 tokenExpiresIn 传递给 AuthServiceProvider 引导函数

    您确定您的 AuthServiceProvider 设置正确,如文档中所述吗?

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Passport::routes();
        Passport::tokensExpireIn(now()->addDays(15));
        Passport::refreshTokensExpireIn(now()->addDays(30));
    }
    

    https://laravel.com/docs/5.6/passport#configuration

    ----- 编辑

    根据文档,个人访问令牌总是长期存在的。

    个人访问令牌总是长期存在的。使用 tokensExpireIn 或 refreshTokensExpireIn 方法时,它们的生命周期不会被修改。

    https://laravel.com/docs/5.6/passport#personal-access-tokens

    在这个 Github Issue 中好像有一个 ServiceProvider 可以解决你的问题

    https://github.com/laravel/passport/issues/162

    【讨论】:

    • 我为 Passport 创建了一个单独的 ServiceProvider。当我调用 /oauth/token 时,令牌的生命周期很好,只有在 createToken for user model 中不起作用。
    • 我发现了一个 Github 问题,可能会为您提供解决方案
    猜你喜欢
    • 2021-11-01
    • 2019-12-04
    • 2017-07-27
    • 2017-09-14
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2022-12-26
    • 2017-01-19
    相关资源
    最近更新 更多