Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JWT Token could not be verifed before

Tags:

jwt

I am currently using JWT since the past month and I had no issues. But since yesterday, I am experiencing this error as per below

com.auth0.jwt.exceptions.InvalidClaimException: The Token can't be used before...

I understand there is a timestamp when generating the token and the token cannot be verified before that. The token is being verified on another server. But all this time, it was fine. Can someone advise?

Thanks,

like image 429
ashley Avatar asked Sep 25 '17 06:09

ashley


People also ask

How do I fix JWT error?

Resolution. Ensure that the variable referenced in the <Source> element of the Decode JWT policy is defined, contains a valid (decodable) JWT and is available in the specific flow where the Decode JWT policy is being executed.

Why is my JWT token invalid?

Client machine's time is not synced with NTP server, and caused JWT Token to become invalid due to a token TTL timeout.

Do I need to verify JWT?

Tokens should be verified to decrease security risks if the token has been, for example, tampered with, misused, or has expired. JWT validation checks the structure, claims, and signature to assure the least amount of risk.


2 Answers

If you are using auth0-spring-security-api then you can customize leeway as follow:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Value(value = "${auth0.audience}")
private String apiAudience;

@Value(value = "${auth0.issuer}")
private String issuer;

@Override
protected void configure(HttpSecurity http) throws Exception {      
    final JwkProvider jwkProvider = new JwkProviderBuilder(issuer).build();
    JwtAuthenticationProvider jwtAuthenticationProvider = new JwtAuthenticationProvider(jwkProvider, issuer,
            apiAudience);
    jwtAuthenticationProvider.withJwtVerifierLeeway(3);

    JwtWebSecurityConfigurer.forRS256(apiAudience, issuer, jwtAuthenticationProvider).configure(http)
            .authorizeRequests().antMatchers("/**").authenticated();
}
like image 118
xProgramery Avatar answered Oct 11 '22 18:10

xProgramery


Perhaps try viewing your JWT token using https://jwt.io/ - can you ascertain whether it has expired? Take the exp value (likely epoch) and convert - https://www.epochconverter.com/

You have added very little info in the question to offer any further details. You could try (re-) authenticating with the IDP that issued you the JWT token last time, and check whether that resolves your issue too.

Based on your last comment, do the servers have any clock skew?

like image 23
arcseldon Avatar answered Oct 11 '22 20:10

arcseldon