我不明白如何使用offline_access。你能发给我一个例子吗?我在哪里可以获得新的刷新令牌?
我为所有用户添加了offline_access。我该如何使用这个?用于生成新的刷新令牌。
我有这个方法
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => $client,
'clientSecret' => $secret,
'redirectUri' => 'https://site/xeroreports',
'urlAuthorize' => 'https://login.xero.com/identity/connect/authorize',
'urlAccessToken' => 'https://identity.xero.com/connect/token',
'urlResourceOwnerDetails' => 'https://identity.xero.com/resources'
]);
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $xero_refresh
]);
但我只得到访问令牌
如果我使用
$client = new \GuzzleHttp\Client();
$response1 = $client->request('POST', 'https://identity.xero.com/connect/token', [
'body' => '{"grant_type":"refresh_token", "refresh_token":"'. $xero_refresh .'"}',
'headers' => [
'Authorization' => 'Basic ' . $authpas,
'Content-Type' => "application/x-www-form-urlencoded",
],
]);
echo $newRefreshToken = $response1->getBody();
我有一个错误
Type: GuzzleHttp\Exception\ClientException Code: 400 Message: Client error: `POST https://identity.xero.com/connect/token` resulted in a `400 Bad Request` response: {error: unsupported_grant_type}
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $xero_refresh
]);
在上面的代码片段中,
$newAccessToken
不是一个字符串,而是一个对象。要获取新的刷新令牌,只需如他们的 $newAccessToken->getRefreshToken()
中所述。
您将
wiki
设置为
content-type
,但正文作为 JSON 对象传递。以下代码应该有效:
application/x-www-form-urlencoded