medusajs/medusa · error · MedusaError
id_token is missing 'sub' claim
Error message
id_token is missing 'sub' claim
What it means
The decoded and signature-verified id_token from Medusa Cloud is missing the 'sub' (subject) claim, which the provider uses as the entity id for the auth identity. Without it the identity cannot be mapped, so authentication aborts.
Solutions
- Inspect the id_token payload (decode the middle segment) to confirm which claims are present
- Fix the IdP/Cloud configuration so standard OIDC 'sub' is included in issued tokens
- If testing, use a properly formatted JWT containing sub and email_verified
Defensive patterns
Strategy: try-catch
Try / catch
try { await validateCallback(...) } catch (e) { if (e.message.includes("missing 'sub'")) { /* flag IdP token config issue */ } throw e } Prevention
- Use well-formed OIDC tokens containing sub in test fixtures
- Audit custom IdP claim mappings after upgrades
When it happens
Trigger: validateCallback receives an id_token whose payload lacks 'sub' — typically a misconfigured or nonstandard token issued by the identity provider, or a hand-crafted/debug token used in tests.
Common situations: Custom IdP configurations that drop standard OIDC claims; stale test fixtures with truncated JWTs; IdP version/config change that altered token claims.
Related errors
- UNAUTHORIZED
- A 'state' value is required to build the authorization URL
- An active TOTP factor already exists for this auth identity
- An authorization 'code' is required to exchange for tokens
- Auth identity does not have any enabled MFA methods
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/5d30bdd950c96625.
Report an issue: GitHub.
Appendix: source
Thrown at packages/modules/auth/src/providers/medusa-cloud-auth.ts:224
throw new Error("Invalid id_token")
}
payload = decoded
} catch (err) {
return {
success: false,
error: `Could not verify id_token: ${err.message}`,
}
}
if (!payload.email_verified) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Email not verified, cannot proceed with authentication"
)
}
if (!payload.sub) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"id_token is missing 'sub' claim"
)
}
const entity_id = payload.sub
const userMetadata = {
name: payload.name,
email: payload.email,
picture: payload.picture,
given_name: payload.given_name,
family_name: payload.family_name,
}
let authIdentity
try {
authIdentity = await authIdentityService.retrieve({View on GitHub (pinned to 5e06e544a2)