OAuth 2.0OIDCJWTSession TokensAccess TokenRefresh TokenAuthentication

Authentication

Master authentication patterns — OAuth 2.0 & OpenID Connect, JWT vs session tokens, token refresh strategies, and secure identity verification for modern APIs.

28 min read8 sections
01

The Big Picture — What Is Authentication?

Authentication answers one question: "Who are you?" It's the process of verifying a user's identity — proving that the person making a request is who they claim to be. It's the first gate every request must pass through before the system decides what that person is allowed to do.

🛂

The Airport Security Analogy

Authentication is showing your passport at the airport — it proves your identity. The officer checks: is this a real passport? Does the photo match? Is it expired? Once verified, you get a boarding pass (token). Authorization is what happens next: the boarding pass says you can board Flight 42 to Tokyo, but not Flight 99 to London. You've proven WHO you are (authentication), and the boarding pass defines WHAT you can access (authorization). In software: logging in = authentication. Checking if you can delete a post = authorization.

🪪

Authentication (AuthN)

WHO are you? Verify identity via credentials (password, biometrics, OAuth). Result: a token proving your identity.

🔐

Authorization (AuthZ)

WHAT can you do? Check permissions based on your identity. Result: allow or deny access to a resource.

🔥 Key Insight

Authentication and authorization are separate concerns. You can be authenticated (proven identity) but not authorized (no permission). A junior employee has a valid badge (authenticated) but can't enter the server room (not authorized). Always design them as independent layers.

1 / 8