API 401 vs 403 Debugging Guide

Separate missing authentication from denied authorization. Last updated September 1, 2026.

Debug 401 Unauthorized and 403 Forbidden API responses with headers, tokens, scopes, roles and gateway evidence. This Formalint reference is written for working developers, DBAs and support engineers who need a repeatable debugging path instead of a one-line snippet with no context.

Use the notes below as a practical review order: understand the input, capture evidence, make one small change and verify the result before moving to the next assumption.

When to use this page

Separate missing authentication from denied authorization. It is most useful when a small validation or debugging mistake can create noisy tickets, misleading logs or hard-to-review production changes.

Practical workflow

StepWhat to confirm
Read the status literally401 usually means authentication is missing or invalid; 403 usually means identity is known but not allowed.
Capture auth headersCheck WWW-Authenticate, request Authorization and any gateway error metadata.
Compare identity to permissionDecode safe token samples, then verify scopes, roles, tenant and resource ownership.

curl evidence to capture

curl -i https://api.example.com/resource \
  -H "Authorization: Bearer TOKEN" \
  -H "Accept: application/json"

Review checklist

  1. Confirm the token is being sent to the same host that validates it.
  2. Check expiration, issuer, audience and clock skew.
  3. Compare the failing user with a known working user.
  4. Inspect gateway, application and identity-provider logs separately.
  5. Never paste real bearer tokens into browser tools or chat logs.

Common mistake

Teams often rotate tokens when the real problem is a missing scope or tenant mismatch. The status code is a clue, not the full diagnosis.

Formalint is strongest when the page helps the developer decide what the tool cannot prove. Treat every formatter, regex and command as one layer of evidence, not the whole truth.

Frequently asked questions

Can a 403 be fixed by logging in again?

Sometimes, but only if the session lost permission context. Usually the role or resource rule must be checked.

Should APIs reveal why access failed?

Enough detail for debugging is useful, but public responses should avoid leaking sensitive authorization rules.

Related Formalint references

Continue with OAuth JWT Debugging Checklist, JWT Decoder, API Debugging Checklist.