我按照文章OAuth authorization code grant流程获取令牌
最初我提出了请求:
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
吗?
答案 0 :(得分:1)
最后工作了, 从早期的步骤获取代码后,我做了一个php请求看起来像::
$ client = new 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));
响应包含accesstoken和刷新令牌。
答案 1 :(得分:0)
检查第二步
https://myinstance.servicenow.com/oauth_auth.do?grant_type= 代码&amp; code = {auth code}&amp; redirect_uri = {the_same_redirect_url}&amp; client_id = {the_same_client_identifier}
您正在使用
grant_type = authorization_code