v1.0.3

Status Codes and Error Tags

Last updated


Every method reports through JWTAuthResult; this page lists what triggers each StatusCode and ErrorTag combination.

Mapping


StatusCodeErrorTagSourceTrigger
400data_missingCreateauth is nil
400data_missingRevokeThe request has no Refresh ID
400data_invalidVerifyBad signature, nbf not reached, iat more than 5 minutes in the future, claim Refresh ID or fingerprint mismatch, JTI missing from Redis or the EXISTS jti: call failing
401unauthorizedVerifyNeither an Access Token nor a Refresh ID
401unauthorizedRefreshRefresh ID absent, expired, or fingerprint mismatch
401unauthorizedRevokeRefresh ID absent or expired
401revokedVerifyThe Access Token has been revoked
401(empty)RefreshCheckAuth returned false or an error
429failed_to_updateRefreshThe refresh lock for this Refresh ID is held, or the SETNX call fails
500failed_to_createCreate, refreshRefresh ID or refresh data serialization failed
500failed_to_signCreate, refreshJWT signing failed (for example, the key is not P-256)
500failed_to_storeCreate, refresh, RevokeRedis write failed
500failed_to_getVerify, RevokeRedis read failed

"Refresh" means the Transparent Refresh triggered inside Verify; its result is returned by Verify.

The Error Field


Error is a human-readable message that may embed underlying error strings (from Redis or the JWT library); do not return it to end users or branch on it. Branch on StatusCode and ErrorTag only.
On failure the middleware returns only {"error": Error}, without ErrorTag (see Middleware).

Handling by Tag


  1. result := auth.Verify(w, r)
  2. if !result.Success {
  3. switch result.ErrorTag {
  4. case "revoked", "unauthorized", "":
  5. http.Error(w, "please sign in", http.StatusUnauthorized)
  6. case "failed_to_update":
  7. w.Header().Set("Retry-After", "1")
  8. http.Error(w, "retry", http.StatusTooManyRequests)
  9. case "data_invalid", "data_missing":
  10. http.Error(w, "invalid credentials", http.StatusBadRequest)
  11. default:
  12. log.Printf("go-jwt: %s", result.Error)
  13. http.Error(w, "internal error", http.StatusInternalServerError)
  14. }
  15. return
  16. }
中文