首页 > 解决方案 > 为 JWT 用户令牌调用 DocuSign API 时出现错误请求。同意?

问题描述

我正在使用 DocuSign API 来请求 JWT 用户令牌:

with open('docusign.pem', mode='rb') as privatefile:
    private_key_bytes = privatefile.read()
api_client = ApiClient()
oauth_host_name = 'account-d.docusign.com'
# not real, random:
client_id = 'dff16ff1-de93-477d-a73d-3774ac9932dc'
user_id = '7401f22e-ff2c-4777-9117-5932ace2e71a'
expires_in = 3600
result = api_client.request_jwt_user_token(client_id, user_id,
                                       oauth_host_name,
                                       private_key_bytes,
                                       expires_in,
                                       scopes=(OAuth.SCOPE_SIGNATURE,))

这将返回:

(400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Cache-Control': 'no-cache', 'Pragma': 'no-cache',
'Content-Type': 'application/json; charset=utf-8', 'Expires': '-1', 'Server':
'Microsoft-IIS/10.0', 'X-AspNetMvc-Version': '5.2', 'X-DocuSign-TraceToken':
'c1d090b7-cefd-4881-80c6-3f1c55ccc5b4', 'X-Content-Type-Options': 'nosniff',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload,
max-age=15768000', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block;
report=/client-errors/xss', 'X-DocuSign-Node': 'DA2DFE179', 'Date':
'Sun, 23 Aug 2020 15:18:46 GMT', 'Content-Length': '28'})
HTTP response body: b'{"error":"consent_required"}'

那么如何获得“同意”。此页面有两个部分“内部应用程序的管理员同意”和“外部应用程序的管理员同意”:

DocuSign 获得同意

我不确定如何在沙盒中获得同意。它已经在 DocuSign 中的用户的“权限配置文件”下显示“DS Admin”。

更新

我使用第二种技术“内部应用程序的管理员同意”来获得对设置的同意:

admin_consent_scope=impersonation
response_type=code
scope=openid

而不是登录,我在 DocuSign 网站上收到消息:“您不是组织管理员。请联系您的 DocuSign 管理员。”

如何要求 DocuSign 在我的开发者帐户上启用此功能?

标签: pythonpython-3.xdocusignapi

解决方案


请参阅有关授予同意的博客文章

请注意,被模拟的用户需要同意signature范围(如果您使用电子签名功能)和impersonation范围。

对于个人同意,两个范围由一个空格分隔,该空格应输入为%20编码值。

例子:

https://account-d.docusign.com/oauth/auth?
response_type=code
&scope=signature%20impersonation
&client_id=YOUR_INTEGRATION_KEY

推荐阅读