Error "subject token is invalid" Occurs During Okta OAuth 2.0 Token Exchange Flow
Last Updated:
Overview
An invalid subject token error occurs during an OAuth 2.0 On-Behalf-Of Token Exchange because the Okta Authorization Server cannot validate the token. Resolve this issue by inspecting the token claims to ensure the token remains unexpired and the audience and issuer match the expected values. When an application attempts to perform an OAuth 2.0 On-Behalf-Of Token Exchange using the grant type urn:ietf:params:oauth:grant-type:token-exchange, the request to the /token endpoint fails, and Okta returns the following error:
{ "error": "invalid_grant", "error_description": "subject token is invalid" }
Applies To
- Okta Identity Engine (OIE)
- Okta Classic Engine
- OAuth 2.0 / OpenID Connect (OIDC)
- Token Exchange Grant Type
Cause
This error occurs because the Okta Authorization Server cannot validate the subject_token. There are several common causes for this validation failure:
- Expired token: The
subject_tokenis expired. The expiration time is checked via theexpclaim. - Invalid Audience: The
aud(audience) claim in thesubject_tokenis not theclient_idof the application that is making the token exchange request. - Issuer mismatch: The
iss(issuer) of the token is for a different authorization server than the authorization server of the token endpoint being called.
Solution
What steps resolve the subject token validation failure?
Inspect the subject_token (for example, using a tool like jwt.io) to confirm the claims are correct by verifying the expiration, audience, and issuer values.
- Check the
expclaim to ensure the token remains unexpired. - Check the
audclaim to verify that this claim exactly matches the Client ID of the application making the request to the/tokenendpoint. - Check the
issclaim to confirm that the authorization server in the issuer claim matches the authorization server used in the token call.
