如何在刷新访问令牌时在 docusign 中请求扩展范围刷新令牌

How to request for an extended scope refresh token in docusign while refreshing access token

我在为 oauth 代码授权流生成授权 URI 时包含了 'extended' 范围,但是在刷新访问令牌时,在响应中我得到的范围是 'signature'。刷新访问令牌时如何获取具有扩展范围的刷新令牌。我已附上我的代码以从刷新令牌获取访问令牌。

        auth_string = "{0}:{1}".format(
            DOCUSIGN_CLIENT_ID, DOCUSIGN_CLIENT_SECRET
        )
        auth_encoded_hash = b64encode(auth_string.encode("utf-8"))
        auth_header = auth_encoded_hash.decode("utf-8")

 
        url = "https://account-d.docusign.com/oauth/token"

        headers = {
            "Authorization": "Basic {0}".format(auth_header),
            "Content-Type": "application/x-www-form-urlencoded",
        }

        body = {"grant_type": "refresh_token", "refresh_token": refresh_token}
        _response = requests.post(url, data=body, headers=headers)
        response = _response.json() # here I am getting scope as 'signature'

我的第二个跟进问题是,如果刷新令牌本身在刷新访问令牌时过期,我将在上面的响应中收到什么错误消息?

当您最初同意并从用户那里获取令牌时,需要“扩展”范围,以便刷新令牌在 30 天内不会过期。每次使用所述刷新令牌获取新访问令牌时都不需要它。

过期令牌的错误消息通常会收到 无效授权 错误,但该错误可能会发生变化,您应该处理所有错误而不是寻找特定的错误字符串.

参见 了解类似的 question/answer。

刷新操作请求不包括范围。 刷新操作 response 可能包括之前请求的范围。

这里是刷新操作:

curl --location --request POST 'https://account-d.docusign.com/oauth/token' \
--header 'Authorization: Basic 'NWYxZTg4…………...TJkOGI2Yg==' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'refresh_token=eyJ0eX…………...Dp_hA' \
--data-urlencode 'grant_type=refresh_token'

如果刷新操作成功,则响应包含一个新的访问令牌和一个新的刷新令牌。

接下来,扔掉旧的刷新令牌,使用新收到的刷新令牌直到下一次。

换句话说:

  • 第一次刷新 API 调用使用授权码授权流程返回的刷新令牌
  • 然后每次后续刷新 API 调用都使用先前刷新 API 调用返回的刷新令牌

Blog post about using refresh tokens