Skip to content

Troubleshooting guide

401 Unauthorized: causes, fixes and how it differs from 403

A 401 means the server does not know who you are. No valid credentials arrived, whether they were missing, expired, malformed or removed on the way there.

4 min read10 sectionsUpdated

On this page

Key points

  • 401 is about identity; 403 is about permission.
  • Expired tokens are the most common cause in APIs and single-page apps.
  • Proxies can strip the Authorization header, especially across redirects.
  • The WWW-Authenticate response header often says exactly what was wrong.

What 401 means

Despite the name, 401 means unauthenticated. The server is saying: I cannot identify you, so prove who you are and try again. A correct 401 response includes a WWW-Authenticate header naming the scheme it expects.

The difference from 403 is practical. Refreshing your token can fix a 401. No new token fixes a 403 if the account simply lacks access, so the two need different handling in client code.

Common causes

  • Expired access token. Short-lived JWTs expire and the client did not refresh them.
  • Missing header. Code built the request without credentials, or a browser did not send cookies on a cross-site call.
  • Wrong scheme. Authorization: token abc where the API requires Bearer abc.
  • A proxy dropped the header. Some HTTP clients deliberately remove Authorization when following a redirect to another host.
  • Clock skew. A server whose clock is minutes off will reject tokens as not yet valid or already expired.
  • Rotated signing keys where one instance still holds the old key, which produces intermittent 401s.

Diagnose it

Read the response headers first, then inspect the token itself. If you use JWTs, decode the payload and compare exp with the current time.

bash
# Show the challenge the server sends
curl -si https://api.example.com/me -H "Authorization: Bearer $TOKEN" | grep -iE '^(HTTP|www-authenticate)'

# Decode a JWT payload (no verification, for inspection only)
echo "$TOKEN" | cut -d. -f2 | base64 -d 2>/dev/null; echo

# Compare the clock with a trusted time source
date -u; timedatectl status | grep -i synchronized

Fixes

Refresh tokens before expiry and retry once on 401, but only once, or an invalid refresh token becomes an infinite loop. Configure your proxy to pass the header: on Nginx, proxy_set_header Authorization $http_authorization;. For cross-site browser calls, send cookies explicitly and set SameSite=None; Secure. Run NTP on every host. When rotating signing keys, publish the new key to all verifiers before you start signing with it.

Catch it automatically

Intermittent 401s usually mean one bad instance or a key rotation in progress, so break the 401 rate down by host in APM. For login itself, run a multi-step synthetic check so an authentication outage reaches you before your users report it. Log the failure reason, such as expired or bad signature, and never log the token.

Frequently asked questions

What is the difference between 401 and 403?

401 means the server does not know who you are. 403 means it knows and refuses. A new token can fix a 401, while a 403 needs a change in permissions.

Why does my API call work in Postman but return 401 in the browser?

Browsers apply CORS and cookie rules that Postman does not. Check that the Authorization header survives the preflight and that cross-site cookies are allowed by SameSite.

Should a client retry after a 401?

Refresh the credential and retry once. If it still fails, stop and send the user to sign in again.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.