dtm41506 2019-04-09 19:08
浏览 227

如何在Laravel Passport中获取所有用户的访问权限?

For background we have two servers: the oauth server which issues out tokens and has laravel passport installed, and an api server which handles requests for the front end. In order to minimize requests, we are caching the access token on the api server, so that there is no need to make a request out to the oauth server from the api server.

However, in the case of an emergency, we want to quickly invalidate all of a user's tokens and remove the tokens from the cache on the api server.

I have figured out how to invalidate all of a user's tokens, but getting the actual access token value proves to be difficult. Is there a way to get a user's access tokens and return them to the api server?

For reference, here is the code I have to currently invalidate a user's tokens:

use App\User;

public function invalidate_sessions($user_id) {
    $user = User::find($user_id);

    $tokens = [];
    foreach ($user->tokens as $token) {
        $token->revoke();
        // this doesn't work
        $tokens[] = $token;
    }
    $api_server = config('auth.api_server');
    $http = new \GuzzleHttp\Client;

    $response = $http->post("{$api_server}/api/invalidate_sessions", [ 
        \GuzzleHttp\RequestOptions::JSON => $tokens
    ]);

    return (string)$response->getBody();
}
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式