【问题标题】:Laravel Passport invalid refresh token - token is not linked to clientLaravel Passport 无效的刷新令牌 - 令牌未链接到客户端
【发布时间】:2019-01-25 05:00:03
【问题描述】:

我在 Laravel 5.5 上使用 Passport,尝试刷新访问令牌时收到错误 - 仅在生产服务器上 - 本地开发环境工作正常!

这是返回的错误:

{
"error": "invalid_request",
"message": "The refresh token is invalid.",
"hint": "Token is not linked to client"
}

我已验证令牌和客户端存在于数据库中、未过期、未撤销、已正确存储等。

因为系统是多租户系统(每个租户都有自己的数据库)我没有使用命令创建护照客户端

php artisan passport:client

相反,我为每个租户复制了护照 oauth_clients 表和内容 - 以便每个租户使用相同的客户端凭据,例如从前端登录、从应用程序登录(但使用不同的端点)。

我不知道为什么它在我的本地机器上运行良好,但在生产环境中却不行。

除了在oauth_clients 表中创建一行之外,有谁知道php artisan passport:client 究竟做了什么?

我在想,可能需要的不仅仅是复制 oauth_clients 表内容..

任何建议表示赞赏!谢谢

【问题讨论】:

  • 分享你是如何创建刷新令牌的,以及你在本地存储和重新发送的位置?

标签: laravel oauth laravel-passport


【解决方案1】:

在深入研究供应商代码后,我通过修改解决了问题

供应商/联盟/oauth2-server/src/Grant/RefreshTokenGrant.php

函数 validateOldRefreshToken

改变了

if ($refreshTokenData['client_id'] !== $clientId) {
        $this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request));
        throw OAuthServerException::invalidRefreshToken('Token is not linked to client');
    }

if ($refreshTokenData['client_id'] != $clientId) {
        $this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request));
        throw OAuthServerException::invalidRefreshToken('Token is not linked to client');
    }

即使 $clientId 匹配,函数也会传递一个字符串(根据需要),但 $refreshTokenData['client_id'] 是一个整数。

fml.

【讨论】:

    猜你喜欢
    • 2020-09-14
    • 2018-04-23
    • 2019-02-20
    • 2018-12-08
    • 2018-02-01
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多