DocuSign API JWT问题(Python)

2024-09-27 21:24:40 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用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]中找到的帐户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提供的库来完成的

不太清楚从这里到哪里去,但任何帮助都是感激的


Tags: keyclienttokenapiidhostforbase
1条回答
网友
1楼 · 发布于 2024-09-27 21:24:40

以下是一些可能有帮助的信息

在DocuSign中,您拥有属于帐户-用户的帐户和成员资格。 因此,userId是一回事(GUID),accountID是另一回事(GUID)。 您只能从您所属的帐户访问信封。 使用JWT时,必须提供用户ID才能获取访问令牌。 这些调用是通过模拟此用户进行的。如果你试图从一个用户没有会员资格的帐户访问一个信封(或任何东西),你会得到你得到的错误

最后一件事,请确保所有工作都在同一个anv中完成。也就是说,如果Oauth是在demo/developer(account-d.docusign.com)中完成的,那么API调用将对同一个env(demo.docusign.net)进行。如果使用account.docusign.com(生产),则API调用需要指向正确的URL,该URL不是demo.docusign.net(但可以是na3.docusign.net或eu1.docusign.net等)

相关问题 更多 >

    热门问题