What 401 means
The request needs authentication and it’s missing or didn’t work. Despite the name, it means unauthenticated (“who are you?”), not unauthorised. The response must include a WWW-Authenticate header saying how to authenticate.
When servers send it
When there are no credentials, or the token, password or API key is wrong, expired or revoked.
Common causes
- An expired access token (JWTs often last only 5 to 60 minutes).
- No
Authorizationheader, or a typo such asBearermissing. - A proxy or CDN stripping the
Authorizationheader. - A clock difference between machines making a fresh token look expired or not yet valid.
How to fix it as a developer
- Check the token’s
expandnbfclaims with the JWT decoder. - Send it as
Authorization: Bearer <token>, with one space and no quotes. - Refresh tokens before they expire, and retry once after refreshing on a 401.
- As the server, include
WWW-Authenticate, and use 403 (not 401) when you know who the user is but they lack permission.
How to fix it as a visitor
- Log in again. Your session may have expired.
- If you’re logged in, log out and back in, or clear cookies for the site.
Related codes
- 403 Forbidden: The server understood who you are and won’t let you do this.
- 407 Proxy Authentication Required: Like 401, but it’s a proxy between you and the server that wants you to log in.
- 404 Not Found: There’s nothing at this URL, or the server won’t say whether there is.
- 419 Page Expired: Laravel’s code for a form whose security (CSRF) token has expired or is missing.
Where it’s defined
401 Unauthorized is defined in RFC 9110, section 15.5.2. It’s a 4xx code, the client error class: something is wrong with the request, so sending it again unchanged won’t help.
Other 4xx codes
400 Bad Request · 402 Payment Required · 403 Forbidden · 404 Not Found · 405 Method Not Allowed · 406 Not Acceptable · 408 Request Timeout · 409 Conflict · 410 Gone · 413 Content Too Large · 414 URI Too Long · 415 Unsupported Media Type · 418 I’m a teapot · 422 Unprocessable Content · 429 Too Many Requests · 431 Request Header Fields Too Large · 451 Unavailable For Legal Reasons · 499 Client Closed Request
Or search them all in the HTTP status code list.
Questions people ask
What does HTTP 401 Unauthorized mean?
What’s the difference between 401 and 403?
Does a 401 need a WWW-Authenticate header?
WWW-Authenticate with at least one challenge, such as Bearer or Basic.Why do I get 401 with a token that works elsewhere?
Authorization header, or the server’s clock is off.