小编Kir*_*rit的帖子

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

我正在使用 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 …
Run Code Online (Sandbox Code Playgroud)

api oauth-2.0 xero-api

7
推荐指数
1
解决办法
5597
查看次数

标签 统计

api ×1

oauth-2.0 ×1

xero-api ×1