How to handle expiry when Authentication Server and Recourse server have different time zones #924
-
My Authentication Server is in the Timezone UTC while the Resource servers are distributed microservices with different timezones, some have UTC+ and some have UTC- time zones. Sometimes My Resource servers give expired token exceptions while the actual difference between This happened because the expiration date in the token was generated by UTC timezone while the library was comparing to the resource server's current time. Is there a way by which I can override the expiry by ourselves as per our needs? The library should only check whether the signature is valid or not. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
The dates in a JWT are:
Because of this, the timezone of the local system should not matter. Are the clocks on your servers set to UTC or a localized time? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm not sure I understand. Are you saying there is an issue in JJWT or something you are trying work around in your environment? Does your microservice running in Ohio, have it's system clock set to UTC-05? (or the actual UTC time)? I would like to understand what is going on in more detail, but if this an environment issue you are working around, take a look at the Custom Clock section of the readme. |
Beta Was this translation helpful? Give feedback.
-
As @bdemers pointed out, you will probably want to use the custom create your own |
Beta Was this translation helpful? Give feedback.
-
I wanted to add a general comment that may or may not help you (given your specific company/project constraints), but I feel it is important for any casual readers that might come across this thread in the future: Really, all clocks in all machines in a company's infrastructure should be tightly controlled to always be set to UTC when booting. As someone supporting production architectures for 25 years, I can't tell you the number of times I've seen problems due to non-UTC clocks, from things like this, to log entry problems, telemetry and/or analytics confusion, application side-effects, etc. The amount of productivity lost due to this problem is insidious. As such, applications, in their own code, and only when absolutely necessary, should convert any generated or stored timestamps from UTC to a local time zone at the time it is required, which ideally should only be in a user interface. For example, to show an end-user information in their own timezone. Especially when security concepts exist, like in JWTs, you will save yourself a world of trouble, pain, and debugging/logging sessions if you standardize UTC everywhere. If you're running infrastructure on AWS (for example), EC2 instances can be sync'd with microsecond precision (for free) using the AWS Time Sync Service on both Linux and Windows. Or otherwise just sync with well-known atomic clocks around the world. I do understand engineers sometimes cannot control production infrastructure clock settings, but they should do everything they can to ask their management or customers that all system clocks are normalized to UTC whenever possible (and not just ignore the problem). If not addressed, there will be downstream problems for the organization and/or projects over time. I've seen it SO many times. |
Beta Was this translation helpful? Give feedback.
Sorry, I'm not sure I understand. Are you saying there is an issue in JJWT or something you are trying work around in your environment?
Does your microservice running in Ohio, have it's system clock set to UTC-05? (or the actual UTC time)?
If the system clock is set to something else this would have potential problems for other security mechanisms too.
I would like to understand what is going on in more detail, but if this an environment issue you are working around, take a look at the Custom Clock section of the readme.