我正在使用 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)