【问题标题】:Service now oauth grant flow error with oauth_token.dooauth_token.do 的服务现在 oauth 授予流错误
【发布时间】:2017-07-28 19:45:36
【问题描述】:

我按照OAuth authorization code grant的文章流获取token

最初我提出了要求:

dev234.service-now.com/oauth_auth.do?response_type=code&client_id=****534e4e81b7f

以及允许访问后的响应:

http://callback-url?code=Z2YYGhgfh1tMoFPDO7Dr0nZuPnhQPs53qwkm_Sw99gpUf92gU3x_OOuoOqdYBvlPFF01pOfgZg9VoXpCruSRYQ

之后获取token:

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_tokenrefresh_token 吗?

【问题讨论】:

    标签: oauth oauth-2.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)); 
    

    响应包含访问令牌和刷新令牌。

    【讨论】:

      【解决方案2】:

      检查第二步

      https://myinstance.servicenow.com/oauth_auth.do?grant_type=code&code={授权码}&redirect_uri={the_same_redirect_url}&client_id={the_same_client_identifier}

      你正在使用

      grant_type=authorization_code

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-11
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2019-12-03
      相关资源
      最近更新 更多