zyeek
zyeek

Reputation: 1287

Having issue requesting for a generated token

I am using the python wrapper for docusign docusign-esign.

I am trying to use the token a couple of ways hoping one of them will work. I have gone through the Docusign docs and examples; I am unsure where else to look for help on this.

I will link to docusign's code when posting snippets. So people who aren't familiar with the wrapper could also make sense of it.

I am using 2 methods request_jwt_application_token and request_jwt_user_token.

    results = api_client.request_jwt_application_token(
        DOCUSIGN_INTEGRATOR_KEY,
        DOCUSIGN_OAUTH_BASE_URL,
        private_key_bytes,
        TOKEN_EXPIRATION_IN_SECONDS,
        scopes=(OAuth.SCOPE_SIGNATURE, OAuth.SCOPE_IMPERSONATION)
    )
results:

{'access_token': 'eyJ0eXAiOiJNVCIsImFsZyI6IlJTMjU2Iiwia2lkIjoiNjgxODVmZjEtNGU1MS00Y2U5LWFmMWMtNjg5ODEyMjAzMzE3In0.AQgAAAABAAsADQAkAAAAYTNkZTI3MjMtMmUzYS00ZWUxLWE1NzktY2FjNjA1Z
DE3NDc5BwCAK89-QP_WSAgAgGvyjIP_1kgLAB8AAABodHRwczovL2FjY291bnQtZC5kb2N1c2lnbi5jb20vDAAkAAAAYTNkZTI3MjMtMmUzYS00ZWUxLWE1NzktY2FjNjA1ZDE3NDc5GAACAAAABQAAAB0AAAASAAEAAAAGAAAAand0
X2Jy.FK9nETujvSqQPyvE0LQZVuB-LrBHWUcmgFaqhGfBm9Wk39SlD41OohLRYGrM6SzXohjorSsDzRB9rHF9d9qmdKaj2ZXNGDBsTE3eRUGeYp-0cWRN3qYNQmgfdsqOTAslNiXQdNfgxsBFjaQtKag2f51MZ_xdvMW4iVjB1WMXFP
vf6BaEy5BJWzpdmd0JE5-8UvDhFV2wxLAGSc1d2JaxJbcFMnBt3-xQMmYtCgyJ5SAh9LxU_rAIt7AkoalPHILQjieAh4kupFeQiLJHSjX7o37K6DngG9I0iHXWspW_rMNOH-_70Um_iSPPNI_hnpJZKB3yDMkiuYcXZKFLEf1L7g',
 'data': None,
 'expires_in': '3600',
 'refresh_token': None,
 'scope': None,
 'token_type': 'Application'}

this is the closest I've been able to get when getting a token, however, when to use the token for getting user info api_client.get_user_info(token)

I get

ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'X-DocuSign-Node': 'SE1DFE2', 'Content-Length': '87', 'Expires': '-1', 'Vary': 'Accept-Encoding', 'X-DocuSign-TraceToken': 'e8af89bc-c18
4-45d7-8f9c-a7faff443006', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Date': 'Tue, 02 Jul 2019 22:56:50 GMT', 'Content-Type': 'application/json; charset=utf-8'})
HTTP response body: {"error":"internal_server_error","reference_id":"e8af89bc-c184-45d7-8f9c-a7faff443006"}

I looked up some solutions for this, but that didn't pan out.

I then tried to use

    results = api_client.request_jwt_user_token(
        DOCUSIGN_INTEGRATOR_KEY,
        DOCUSIGN_USERID,
        DOCUSIGN_OAUTH_BASE_URL,
        private_key_bytes,
        TOKEN_EXPIRATION_IN_SECONDS,
        scopes=(OAuth.SCOPE_SIGNATURE, OAuth.SCOPE_IMPERSONATION)
    )

This didn't work at all. Fails to get a token.

results:

Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'X-DocuSign-Node': 'DA1DFE4', 'Content-Length': '27', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'X-Co
ntent-Type-Options': 'nosniff', 'Content-Type': 'application/json; charset=utf-8', 'Expires': '-1', 'Vary': 'Accept-Encoding', 'X-XSS-Protection': '1; mode=block; report=/clie
nt-errors/xss', 'X-DocuSign-TraceToken': 'b5d728bc-a442-4b35-bdb3-3026e64df334', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Date': 'Tue, 02 Jul 2019 23:12:49 GMT', 'X
-Frame-Options': 'SAMEORIGIN', 'X-AspNetMvc-Version': '5.2'})
HTTP response body: {"error":"invalid_request"}

I have gone over https://developers.docusign.com/esign-rest-api/guides/authentication/oauth2-jsonwebtoken and went through the troubleshooting.

Just wondering if anyone has some insight on what the issue may be.

Upvotes: 0

Views: 349

Answers (2)

Inbar Gazit
Inbar Gazit

Reputation: 14015

You need to get a userId for the user you're trying to "impersonate" if you're using a JWT token. You can find that userId by logging to the sandbox.

Upvotes: 1

Larry K
Larry K

Reputation: 49104

To summarize the solution (see the comments with the question):

  1. Check that Implicit Grant is not checked for the Integration Key.
  2. The user Id that will be impersonated is the API Username value from the Users section of the Administration tool. Don't confuse it with the short-form Account Id available near your name in the upper righthand corner of the DocuSign web tools.
  3. Use the SDKs' request_jwt_user_token method to obtain an access token via the JWT Grant flow.

Upvotes: 1

Related Questions