阅读(1258) (6)

Laravel 8 刷新令牌

2021-07-09 11:44:52 更新

如果你的应用程序发放了短期的访问令牌,那么用户需要通过访问令牌颁发时提供的刷新令牌来刷新访问令牌。在下面的例子中,我们使用 Guzzle HTTP 库来刷新令牌:

$http = new GuzzleHttpClient;

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'refresh_token',
        'refresh_token' => 'the-refresh-token',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'scope' => '',
    ],
]);

return json_decode((string) $response->getBody(), true); 

/oauth/token 路由会返回一个 JSON 响应,其中包含 access_tokenrefresh_tokenexpires_in 属性。 expires_in 属性包含访问令牌过期时间(单位:秒)。