Unable to parse JWT through JwtSecurityTokenHandler

Given any JWT I get from Okta, When I get to this part:

JwtSecurityTokenHandler tokendHandler = new JwtSecurityTokenHandler();

				SecurityToken jwt;

				var result = tokendHandler.ValidateToken(v_IdToken, validationParameters, out jwt);

I always get an exception on the ValidateToken method:

IDX12709: CanReadToken() returned false. JWT is not well formed: ‘[PII is hidden]’.\nThe token needs to be in JWS or JWE Compact Serialization Format. (JWS): ‘EncodedHeader.EndcodedPayload.EncodedSignature’. (JWE): ‘EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag’.

This code parses JWT’s from Microsoft Azure just fine, so I’m not sure what the issue is. Any help on this would be appreciated

Example JWT with this problem:

Hey @kenkeir!

Access tokens issued from your root/org URL should be treated as opaque.
For example this one:


The second one can be treated as a JWT and validated.

Does that help?

Unfortunately, I’m not getting anything from this url now.

providing that the <id> is the clientID, the url formatted like this:

this errors out with : error=invalid_request&error_description=The+authorization+server+id+is+invalid.

The url formatted without the v1:
this returns a 400 error on the okta website.

So my thought is that id is not the clientID. What should that value be?

Update to above, I replaced the clientID with default, and I recieved a token again, but I recieve the exact same error as before: CanReadToken() returned false, etc.

I guess I just don’t understand how the jwt from okta is malformed. It is properly subdivided into header, payload, signature. Putting it into an online jwt parser such as jwt.io returns expected data and values.


the issue is that the jwt returned from the auth server contained an end of file escape character (’\0’), which was invisible from a debug text editor, and removed from copy/paste. Removing this character causes the code to work without issue.