invalid_token: The access token is invalid (JsonWebTokenError: invalid signature / jwt malformed)

A token was sent but the server couldn’t verify it — bad signature, malformed, revoked, or issued for another audience or environment.

Exact message you may see JsonWebTokenError: invalid signaturejwt malformedinvalid signaturejwt audience invalidSignature verification failed
Seen on: REST API

Meaning

OAuth 2.0 resource servers answer 401 with WWW-Authenticate: Bearer error="invalid_token". JWT libraries are more specific: “invalid signature” (signed with a different secret/key), “jwt malformed” (not three base64url parts — often the literal string "undefined" or a token with "Bearer " still attached), “invalid audience/issuer” (minted for another API or tenant).

Expiry is a separate case — see TokenExpiredError.

Common causes

  • Verifying with a different secret or public key than the issuer used (env mismatch, key rotation)
  • Token is malformed: "undefined", quotes, or the "Bearer " prefix included
  • Audience/issuer doesn’t match this API
  • Token revoked or the session logged out
  • ID token sent where an access token is required

⚡ Quick fix

  1. Decode the token (jwt.io / base64) and compare iss, aud, kid with the server config
  2. Strip the "Bearer " prefix before verifying
  3. Use the same secret/JWKS as the issuer, refreshed after key rotation
  4. Get a new token

Detailed fix by platform

Node.js

  1. javascript
    const raw = req.headers.authorization?.replace(/^Bearer\s+/i, '');
    const payload = jwt.verify(raw, publicKey, { algorithms: ['RS256'], audience: 'api://orders', issuer: 'https://auth.example.com/' });

Python

  1. jwt.decode(token, key, algorithms=["RS256"], audience="api://orders") # PyJWT: InvalidSignatureError / InvalidAudienceError

How to diagnose

  1. Decode — iss, aud, kid, exp in the token
  2. Key — Which secret/JWKS is the server using?
  3. Format — Exactly what string reaches verify()?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

401 — HTTP 401 Unauthorized (HTTP)401401 — 401 Unauthorized without WWW-Authenticate header (HTTP)401AADSTS50076 — Azure AD (Entra ID): AADSTS50076 / AADSTS50079 — multi-factor authentication required (Azure)AADSTS50076AADSTS50126 — AADSTS50126: Error validating credentials due to invalid username or password (Azure)AADSTS50126AADSTS50173 — AADSTS50173: The provided grant has expired due to it being revoked, a fresh auth token is needed (Azure)AADSTS50173AADSTS700016 — Azure AD (Entra ID): AADSTS700016 Application not found in the directory (Azure)AADSTS700016AADSTS700082 — AADSTS700082: The refresh token has expired due to inactivity (Azure)AADSTS700082Authentication failed — fatal: Authentication failed for 'https://github.com/x/y.git/' (Git)Authentication failedinvalid_t…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.