对于spa仪表板,我使用laravel passport通过CreateFreshApiTokenweb中间件提供api令牌。虽然当用户在操作仪表板中的内容时,在令牌过期后他将无权检索/发布数据,这也是正常的行为。有没有办法通过api刷新cookie令牌?例如:每当用户处于活动状态时,aka就会从api中发布或检索某些内容,cookie令牌将被刷新,因此它只在用户处于非活动状态时才会过期。

最佳答案

如果应用程序发出短命的访问令牌,则用户将需要通过在访问令牌发布时向它们提供的刷新令牌刷新访问令牌。
拉瓦维尔

 $http = new GuzzleHttp\Client;
 $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);

Vuejs公司
created() {
   this.$cookie.set("token", keyValue, "expiring time")
}

07-24 18:15
查看更多