【问题标题】:Passport Password Grant Tokens Refresh护照密码授予令牌刷新
【发布时间】:2017-04-09 20:00:36
【问题描述】:

我执行此问题中描述的步骤:

Laravel's 5.3 passport and api routes

从 api 的路由一切正常,我可以注册新用户,读取他们的数据等。

然后在 AuthServiceProvider 上添加这个命令

Passport::tokensExpireIn(Carbon::now()->addMinute(2)); Passport::refreshTokensExpireIn(Carbon::now()->addDays(1));

我在 url {{url}}/oauth/token 中登录邮递员

正文:application/x-www-form-urlencoded
{
grant_type : '密码'
client_id : {{用户注册的邮箱}}
client_secret : {{从移动应用生成客户端密码}}
用户名:{{用户注册的电子邮件}}
密码:{{用户输入的密码}}
范围:''
}

响应成功

{
"token_type": "持有者"
“expires_in”:120
"access_token": {{access_token}}
“刷新令牌”:{{刷新令牌}}
}

我尝试将令牌生命周期刷新为一天发送到 {{url}}/oauth/token

ref => https://laravel.com/docs/5.3/passport#refreshing-tokens

在邮递员中我发送

标题:

授权:承载{{access_token}}

正文:application/x-www-form-urlencoded
{
client_secret : {{从移动应用生成客户端密码}}
grant_type : refresh_token
刷新令牌:{{刷新令牌}}
client_id : {{用户注册的邮箱}}
范围:''
}

预期的反应:

{
“access_token”:{{新的 access_token}}
"token_type": '持有者'
“expires_in”:86400
“刷新令牌”:{{新访问令牌}}
}

但它没有按预期工作,响应它的

{
“access_token”:{{新的 access_token}}
"token_type": '持有者'
“expires_in”:120
“刷新令牌”:{{新访问令牌}}
}

【问题讨论】:

    标签: api token laravel-5.3 laravel-passport refresh-token


    【解决方案1】:

    因为您使用refresh_token 生成access_token。所以它显示了access_token 的过期时间,即 2 分钟,这是由这一行设置的:

    Passport::tokensExpireIn(Carbon::now()->addMinute(2));
    

    【讨论】:

      【解决方案2】:

      此外,您应该从您的 oauth_clients 表中发送客户 ID(ID 字段整数)...而不是您的客户电子邮件地址

      【讨论】:

        【解决方案3】:
         public function boot()
            {
                $this->registerPolicies();
                Passport::routes();
                Passport::tokensExpireIn(now()->addDays(1));
                Passport::refreshTokensExpireIn(now()->addDays(1));
                Passport::personalAccessTokensExpireIn(now()->addMonths(6));
        
            }
        

        【讨论】:

          猜你喜欢
          • 2017-10-05
          • 2018-02-01
          • 1970-01-01
          • 2023-03-27
          • 2019-05-15
          • 2020-09-08
          • 2017-07-09
          • 2019-11-17
          • 2019-08-06
          相关资源
          最近更新 更多