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 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败