我遵循文章OAuth授权代码授予流来获取令牌
最初,我提出了以下要求:
dev234.service-now.com/oauth_auth.do?response_type=code&client_id=****534e4e81b7f以及在允许访问后的答复:
http://callback-url?code=Z2YYGhgfh1tMoFPDO7Dr0nZuPnhQPs53qwkm_Sw99gpUf92gU3x_OOuoOqdYBvlPFF01pOfgZg9VoXpCruSRYQ在此之后,获得令牌:
dev234.service-now.com/oauth_token.do?grant_type=authorization_code&code=<***>&client_id=<***>&client_secret=<***>当我请求这个时,抛出错误
{"error_description": "access_denied","error": "server_error"}我不能以json格式获得access_token和refresh_token吗?
发布于 2017-04-13 06:39:35
最后,在从前面的步骤中获得代码之后,我使php请求看起来如下:
$client =新客户端();
$post_data = [
'grant_type' => 'authorization_code',
'code' => 'your code',
'redirect_uri' => '<callback_url>',
'scope' => 'useraccount'
];
$auth = base64_encode('<client_id>:<client_secret>');
$res = $client->request('POST', 'https://myinstance.service-now.com/oauth_token.do', [
'headers' => [
'Authorization' => 'Basic ' . $auth,
'Content-Type' => 'application/x-www-form-urlencoded'
],
'form_params' => $post_data
]);
dd(json_decode($res->getBody(), true)); 响应包含访问令牌和刷新令牌。
发布于 2017-03-08 10:34:35
检查第二步
type=code&code={the auth code}&redirect_uri={the_same_redirect_url}&client_id={the_same_client_identifier}
你在用
grant_type=authorization_code
https://stackoverflow.com/questions/42667986
复制相似问题