Xero OAuth2.0 刷新令牌中的无效授予问题

Kir*_*rit 7 api oauth-2.0 xero-api

我正在使用 Xero OAuth2.0 API,一旦令牌过期,我就会刷新令牌。 Xero 文档 我将令牌存储在 JSON 文件中,以便下次可以检索。

错误响应:

{
"error": "invalid_grant"
}
Run Code Online (Sandbox Code Playgroud)

请参考下面我使用过的代码

public function getAccessToken($code = null) {
    if(file_exists($this->tokenPath) && isset($code)) {
        $accessToken = $this->getAccessTokenFromAuthCode($code);
    } else if (file_exists($this->tokenPath)) {
        $accessToken = $this->getAccessTokenFromJSON();
        try {
            if (time() > $accessToken->expires) {
                $accessToken = $this->provider->getAccessToken('refresh_token', [
                    'refresh_token' => $accessToken->refresh_token
                ]);
            }
        } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
            //header('Location: ' . $this->getAuthorizationUrl());
        }

    } else if(isset($code)){
        $accessToken = $this->getAccessTokenFromAuthCode($code);
    } else {
        header('Location: ' . $this->getAuthorizationUrl());
    }

    return $accessToken;
}

public function getAccessTokenFromAuthCode($code) {
    return $this->storeAccessTokenToJSON($this->provider->getAccessToken('authorization_code', ['code' => $code]));
}

public function getAccessTokenFromJSON(){

    return json_decode(file_get_contents($this->tokenPath));
}

public function storeAccessTokenToJSON($accessToken){
    file_put_contents($this->tokenPath, json_encode($accessToken));

    return json_decode(file_get_contents($this->tokenPath));
}
Run Code Online (Sandbox Code Playgroud)

Gar*_*her -1

Invalid_grant 是刷新令牌过期时的标准错误响应代码。

常见令牌生命周期类似于: * 访问令牌 = 60 分钟 * 刷新令牌 = 8 小时

当刷新令牌过期时,您必须让用户重新登录。