1

I have a docusign-sandbox account. I am trying to integrate docusign with my application and am using JWT Grant for authentication in java. I got a sample code from https://github.com/docusign/eg-01-java-jwt and it works perfectly for an hour and then the API starts failing.

Any idea how I can tackle this issue?

I'm getting the below error

I already tried changing the Token expiry time from 1hr to other lesser values(5 min, 30 min). Even then the APIs start failing exactly after an hour.

https://github.com/docusign/eg-01-java-jwt

ERROR MESSAGE

{"timestamp":1560750467288,"status":500,"error":"Internal Server Error","message":"Error while requesting server, received a non successful HTTP code 401 with response Body: '{\r\n  \"errorCode\": \"USER_AUTHENTICATION_FAILED\",\r\n  \"message\": \"One or both of Username and Password are invalid. Invalid access token\"\r\n}'","path":"{path}"}
dj21496
  • 66
  • 6

2 Answers2

3

Found a way around the problem.

The access token was being generated but for some reason it was not updating the token in the ApiClient Object and was using the old token only. So now I am just creating a new ApiClient Object every time the token expires instead of replacing the old token with the new one.

dj21496
  • 66
  • 6
0

The jwt grant returns an access token that is only valid for 1 hour. After that, you need to generate a new token for another hour.

Call the example's checkToken method before each API call. It should create a new access token as needed.

Added

You'll need to debug to see what's happening. Is the checkToken method obtaining a new access token after 50 minutes (it should be using a 10 minute buffer time). Is the new access token being used?

Larry K
  • 42,977
  • 12
  • 82
  • 121
  • Yes, I am calling the checkToken method, and I can see in the logs that it is also generating a new token. But still the API start failing after an hour. – dj21496 Jun 17 '19 at 18:47
  • Yes the the check token method is obtaining a new access token but I see that the auth object in updateParamsForAuth method of ApiClient.java has two values of accessToken. The first time access token is created, both the accessTokens have the same value. the next time when the accessToken expires and a new token is created, only one of the values changes. and i believe its taking the older value. Also, even though i change the value of TOKEN_EXPIRATION_IN_SECONDS the token expires only after an hour. – dj21496 Jun 18 '19 at 07:58
  • Sounds like there may be a bug in the example or how you merged it into your app. At any time, there should only be one access token. Re 1 hour expiration--that's how JWT Grant works. You should just get a new token after ~ 50 minutes. When you find the specific bug, please submit an issue to the Java example's repository. – Larry K Jun 18 '19 at 14:36