I have been trying and testing out Okta as an Identity provider for Login and communication across bunch of Microservices.
Wanted to integrate Token Validation and Claims Decoding at Spring Cloud API Gateway Filters.
As part of this work,
Authentication and Token Fetch, I am doing from Postman, running bunch of APIs getting sessionToken, then Code and then ID and Access Token (by PKCE). All good so far.
Next, My API calls to microservices are routed through API gateway and I am sending Access token as part of each API’s header and interceptor/filers try to decode the Token. Find the error there:
‘’’
com.okta.jwt.JwtVerificationException: Failed to parse token
at com.okta.jwt.impl.jjwt.TokenVerifierSupport.decode(TokenVerifierSupport.java:87)
at com.okta.jwt.impl.jjwt.JjwtAccessTokenVerifier.decode(JjwtAccessTokenVerifier.java:56)
Caused by: io.jsonwebtoken.security.SignatureException: JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:399)
at io.jsonwebtoken.impl.DefaultJwtParser.parse(DefaultJwtParser.java:529)
at io.jsonwebtoken.impl.ImmutableJwtParser.parse(ImmutableJwtParser.java:153)
at com.okta.jwt.impl.jjwt.TokenVerifierSupport.decode(TokenVerifierSupport.java:81)
… 103 more
‘’’
Audience
For Authorization Server I tried using default one, but created a new Auth Server, but the issue persists.
Since I used OIDC + SPA for Application, I only got ClientID without any Client Secret.
So, I cannot use remote /introspect API option because client secret is mandatory in that case.
If you are using custom authZ server then it’s wrong, as custom authZ server definitely uses different issuer URL and audience. Check those out on authZ server page in Okta Admin UI
Hmm, I tried custom Auth Server and audience from the Spring Boot Filter and it was NOT WORKING (same error as above).
But interestingly I ran this simple main with the same token, custom issuer and custom audience and it WORKS just fine and give me claims.
As a follow-on I tried forwarding token to the Spring Boot rest endpoint (from api-gateway) and this jwt verifier code works good at the endpoint.
This doesn’t make any sense to me.
My Spring Cloud API Gateway filter looks like this