首页 > 解决方案 > aws php刷新令牌,没有返回刷新令牌

问题描述

我有 aws sdk php cognito 来刷新令牌,

    public function refreshToken($username, $refreshToken)
    {
        try {
            $response = $this->client->initiateAuth([
                'AuthFlow' => 'REFRESH_TOKEN_AUTH',
                'AuthParameters' => [
                    'SECRET_HASH' => $this->cognitoSecretHash($username),
                    'REFRESH_TOKEN' => $refreshToken
                ],
                'ClientId' => $this->client_id,
            ]);
        } catch (CognitoIdentityProviderException $exception) {
            if ($exception->getAwsErrorCode() === self::NOT_AUTHORIZED) {
                $this->add_error('You are unauthorized to access this resource');
                return false;
            }

            throw $exception;
        }

        return $response;
    }

刷新令牌返回成功 200,但在 AuthenticationResult 中返回 RefreshToken 丢失:

[
    'AuthenticationResult' => [
        'AccessToken' => '<string>',
        'ExpiresIn' => <integer>,
        'IdToken' => '<string>',
        'RefreshToken' => '<string>', // return missing RefreshToken
        'TokenType' => '<string>',
    ],
    ...
]

为什么缺少 AuthenticationResult 中的 RefreshToken?如果无法提供来自initialAuth REFRESH_TOKEN_AUTH 的结果,我无法再次刷新令牌?

标签: phplaravelamazon-cognitoaws-php-sdk

解决方案


推荐阅读