... API 调用 oAuth2.0 刷新令牌问题 PandaDocs

问题描述 投票:0回答:2

我在尝试从 PandaDocs API 上提供的 REFRESH_TOKEN 获取 ACCESS_TOKEN 时遇到问题..

为了从刷新令牌获取新的 ACCESS_TOKEN,要发送的正确参数是什么?

我存储了当我第一次进行身份验证以上传要签名的文档时最初收到的刷新令牌。我现在想使用刷新令牌来获取新的访问令牌,以便检查文档上签名的状态。

我正在尝试使用我存储的刷新令牌获取新的访问令牌,但我不断收到 grant_type 无效。

这是我的代码..

    $token = '(refreshtokenhere)';
    $url = "https://app.pandadoc.com/oauth2/access_token"; 
  $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';
        $ch = curl_init();
        $headr = array();

        $headr[] = 'Content-Type: application/json;charset=UTF-8';


        curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

        $postfields['grant_type'] = 'refresh_token';
        $postfields['refresh_token'] = $token;
        $postfields['client_id'] = CLIENT_ID;
        $postfields['client_secret'] = CLIENT_SECRET;


        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields );


        echo $ret = curl_exec($ch); // 
php curl oauth-2.0 pandadoc
2个回答
2
投票

查看API文档。

grant_type
应包含授权码。

https://developers.pandadoc.com

https://www.rfc-editor.org/rfc/rfc6749

编辑:

grant_type 应该如代码中所示,即文字字符串“refresh_token”。

正如您所发现的,删除内容类型标头,以便正确发送帖子字段。


1
投票

在该令牌字段中您要传递哪个值。它应该包含之前获得的刷新令牌,而不是访问令牌。

© www.soinside.com 2019 - 2024. All rights reserved.