【问题标题】:DocuSign API JWT Issue (Python)DocuSign API JWT 问题 (Python)
【发布时间】:2020-09-26 01:52:31
【问题描述】:

在使用 jwt 方法时,我似乎无法让身份验证正常工作。

这是为应用授权而构建的请求

        uri = api_client.get_authorization_uri(                                                                            
            client_id       = DOCUSIGN_APP_INTEGRATION_KEY,                                                       
            redirect_uri    = WEBHOOK_URL,                                          
            scopes          = ["signature","impersonation"],                                                               
            response_type   = 'code',                                                                                      
        )                                                                                                                  
        uri +="&prompt=login"       

这是获取令牌的 webhook

            api_client  = ApiClient(oauth_host_name = settings.DOCUSIGN_OAUTH_HOST_NAME)                                   
                                                                                                                           
            # Get account id for authed user                                                                               
            xyz = api_client.generate_access_token(                                                                        
                client_id           = DOCUSIGN_APP_INTEGRATION_KEY,                                               
                client_secret       = DOCUSIGN_CLIENT_SECRET_KEY,                                                 
                code                = code,                                                                                
            )                                                                                                              
                                                                                                                           
            resp = api_client.get_user_info(access_token = xyz.access_token)                                               
                                                                                                                           
                                                                                     
            acc_id = resp.sub                                                                                     
            base_uri = ''                                                                                                  
            for account in resp.accounts:                                                                                  
                if account.is_default:                                                                                     
                    base_uri = account.base_uri                                                                                   
                    break                                                                                                  
                                                                                                                           
            token = api_client.request_jwt_user_token(                                                                     
                client_id           = DOCUSIGN_APP_INTEGRATION_KEY,                                               
                user_id             = acc_id,                                                                              
                oauth_host_name     = api_client.get_oauth_host_name(),                                                    
                private_key_bytes   = DOCUSIGN_PRIVATE_KEY,                                                       
                expires_in          = 3600,                                                                                
            )
            
            # Save token.access_token, and base_uri for use elsewhere
            ...               

我也尝试使用从 resp.accounts[0].account_id 找到的帐户 ID(因为该用户只有一个帐户)但在 request_jwt_user_token 上失败并出现此错误

HTTP response body: b'{"error":"invalid_grant","error_description":"user_not_found"}

这一切都很好,但是当我尝试使用这样的令牌在其他地方创建信封时

    # Setup api client with token                                                                                      
        api_client = ApiClient()                                                                                           
        api_client.host = api_base_path # set to https://demo.docusign.net/restapi                                                                                  
        api_client.set_default_header("Authorization", "Bearer " + token)                                                  
        envelope_api = EnvelopesApi(api_client)                                                                            
                                                                                                                           
        try:                                                                                                               
            envelope_resp = envelope_api.create_envelope(                                                                  
                DOCUSIGN_API_USER_KEY,                                                                            
                envelope_definition=envelope_definition                                                                    
            )                                                                                                              
        except ApiException as e:
            ...                                                                                         
                            

我收到此错误

HTTP response body: b'{"errorCode":"USER_DOES_NOT_BELONG_TO_SPECIFIED_ACCOUNT","message":"The specified User is not a member of the specified Account."}'

我也尝试在创建信封时使用 acc_id 而不是 api users 键,但这会出现此错误:

HTTP response body: b'{"errorCode":"PARTNER_AUTHENTICATION_FAILED","message":"The specified Integrator Key was not found or is disabled. Invalid account specified for user."}'

这一切都是通过为python提供的docusign-esign库完成的。

不太确定从这里去哪里,但感谢任何帮助!

【问题讨论】:

    标签: python jwt docusignapi


    【解决方案1】:

    这里有一些信息可能会有所帮助。

    在 DocuSign 中,您拥有帐户和属于帐户一部分的成员资格 - 用户。 因此,userId 是一回事 (GUID),而 accountID 是另一回事 (GUID)。 您只能从您所属的帐户访问信封。 使用 JWT 时,您必须提供 userId 才能获取访问令牌。 这些呼叫是通过冒充该用户进行的。如果您尝试从该用户没有会员资格的帐户访问信封(或任何东西) - 您会收到错误消息。

    最后一件事,请确保所有内容都在同一个 anv 中完成。这意味着,如果 Oauth 在 demo/developer (account-d.docusign.com) 中完成,那么 API 调用将针对相同的 env (demo.docusign.net)。如果您使用 account.docusign.com(生产),则 API 调用必须是正确的 URL,而不是 demo.docusign.net(但可能是 na3.docusign.net 或 eu1.docusign.net 等)

    【讨论】:

    • 是的,看起来我在调用 create_envelope 时使用的是 userId 而不是 accountId,现在它正在工作。感谢您的澄清!
    猜你喜欢
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多