现在使用oauth_token.do服务oauth授予流错误
我按照文章流程获取代币 最初,我提出了以下要求:现在使用oauth_token.do服务oauth授予流错误,oauth,oauth-2.0,Oauth,Oauth 2.0,我按照文章流程获取代币 最初,我提出了以下要求: 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_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=<***>
我不能获取json格式的access\u-token
和refresh\u-token
code&code={the auth code}&redirect_uri={the_same_redirect_url}&client_id={the_same_client_identifier}
您正在使用
授权类型=授权代码
终于成功了,
从前面的步骤中获取代码后,我提出了一个php请求,如下所示:
$client=新客户端()
$post\u数据=[
“授权类型”=>“授权代码”,
“代码”=>“您的代码”,
'重定向_uri'=>'',
'范围'=>'用户帐户'
];
$auth=base64_编码(“:”);
$res=$client->request('POST','https://myinstance.service-now.com/oauth_token.do', [
“标题”=>[
“授权”=>“基本”。$auth,
“内容类型”=>“应用程序/x-www-form-urlencoded”
],
'form_params'=>$post_数据
]);
dd(json_解码($res->getBody(),true));
响应包含accesstoken和refresh token。也尝试过,但没有更改请确保再次运行,因为提供给您的身份验证代码可能已过期。它们非常短暂。感谢您的回复,如果我使用“?…”响应将类似于“不可能以json格式获取…”。。
{"error_description": "access_denied","error": "server_error"}
$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));