RCS
RCS

Reputation: 63

Error when generating DocuSign JWT Token in Java

I've downloaded the JWT Auth sample code

I've gone through and created my integrator app and added private keys.

Modified the ExampleBase.java file for additional logging.

OAuth.OAuthToken oAuthToken = null;
    System.out.println("Client ID: " + DSConfig.CLIENT_ID);
    System.out.println("IUG: " + DSConfig.IMPERSONATED_USER_GUID);
    System.out.println("Scopes: " + scopes);
    System.out.println("Private Key: " + privateKey);
    System.out.println("Token Exp: " + TOKEN_EXPIRATION_IN_SECONDS);

    try {
        oAuthToken = apiClient.requestJWTUserToken(
                DSConfig.CLIENT_ID,
                DSConfig.IMPERSONATED_USER_GUID,
                scopes,
                privateKeyBytes,
                TOKEN_EXPIRATION_IN_SECONDS);

    } catch (IOException e) {
        System.err.println("Error ---IO Exception---");
        System.err.println(e.getMessage());
        System.err.println(Arrays.toString(e.getStackTrace()));
    } catch (IllegalArgumentException e) {
        System.err.println("Error while update/fetching token!");
        System.err.println(e.getLocalizedMessage());
        System.err.println(Arrays.toString(e.getStackTrace()));
    } catch (ApiException e) {
        System.err.println("API Exception!");
        e.printStackTrace();
    }

Code output

Sending an envelope. The envelope includes HTML, Word, and PDF documents. It takes about 15 seconds for DocuSign to process the envelope request... 
Token: null

Fetching an access token via JWT grant...
Client ID: cdb3.......2100207
IUG: 7......6
Scopes: [signature]
Private Key: -----BEGIN RSA PRIVATE KEY-----
MIIEogIBAADrH3w0OwPqp0iSLfDgx3kmiCxdnUW6oGUl
llBBsrkaTrPh4DGbFZhS8XiRbwuAFTWkHbLltYP0VoVHmBUhJomPie9+nAfuSWqh
kll5z/ygcGs7Vrn/mZcXTg4VihLzLphlV4FHBfwneQxq/PVIT0U=
-----END RSA PRIVATE KEY-----
Token Exp: 3600
API Exception!
com.docusign.esign.client.ApiException: Error while requesting an access token: POST https://account-d.docusign.com/oauth/token returned a response status of 400 Bad Request
    at com.docusign.esign.client.ApiClient.requestJWTUserToken(ApiClient.java:740)
    at com.docusign.example.jwt.ExampleBase.updateToken(ExampleBase.java:62)
    at com.docusign.example.jwt.ExampleBase.checkToken(ExampleBase.java:40)
    at com.docusign.example.jwt.SendEnvelope.sendEnvelope(SendEnvelope.java:54)
    at com.docusign.example.jwt.JWTExample.main(JWTExample.java:24)
Done. Continuing...

DocuSign Exception!
    Reason: 0
    Error Reponse: null

Process finished with exit code 0

I'm invoking DocuSign API Client requestJWTUserToken and call fails with 400 Bad Request. Could it be the JSON body or am I missing some else?

Update

After reading online, I figured out that we had to convert the key into pkcs8 format (Java). This really helped me in parsing the keys and generating a Java Keypair. Still running into issues with the generating token.

Upvotes: 0

Views: 1463

Answers (1)

paulsm4
paulsm4

Reputation: 121881

This is a known problem, documented here:

https://github.com/docusign/docusign-csharp-client/issues/187

Hello, The Usage example on the ReadMe works just fine against the Sandbox environment.

However, using the same code but with my production userid, and OAuth base path of "account.docusign.com" returns a 400 Bad Request error.

It is reproducible 100% of the time.

You're coding in Java (not C#), but it sounds like the same issue.

I've already created a ticket, #04233413. There hasn't been any responses from the CS team since June 25th (2018).

SUGGESTION:

Try looking at these links:

Upvotes: 1

Related Questions