The Token is not yet valid

Following the tutorial for Application-restricted RESTful APIs - signed JWT authentication, the call to get the token is returning the following:

{
	"fault": {
		"faultstring": "The Token is not yet valid: policy(VerifyJWT.ClientCredentials)",
		"detail": {
			"errorcode": "steps.jwt.TokenNotYetValid"
		}
	}
}

My current setting are:

Have also tried with endpoint “https://api.service.nhs.uk/oauth2/token

Turns out my system clock was a little ahead that of the Digital.nhs.uk clock, so the start datetime was after the time submitted.

Changed to take the code back by two minutes did a dirty fix to test

 JwtSecurityToken token = new JwtSecurityToken(
        _clientId,
        _audience,
        new List<Claim>
        {
                new("jti", Guid.NewGuid().ToString()),
                new(JwtClaimTypes.Subject, _clientId),
        },
        now.AddMinutes(-2),
        now.AddMinutes(expInMinutes),
        _signingCredentials
    );
1 Like

Thank you for sharing the solution Peter, we appreciate the cooperation

1 Like

I have to say I think you are mistaken. This code is awful! You are obviously doing something wrong, a school boy error! Adding minutes onto a time is just wrong! Please understand the code and try again.

Thank you for your kind words Marcus. And for you constructive criticism.

As you noticed this is a copy of the code from the tutorial and my own inclusion of this being a “dirty fix” to identify the issue, then I am certain you will provide a full and perfect solution.

I await you code solution!

1 Like