OAuth 2.0 Concepts

Understanding the fundamentals of OAuth 2.0.

What is OAuth 2.0?

OAuth 2.0 is an authorization framework that enables applications to obtain limited access to user resources without exposing credentials.

The Problem OAuth Solves

Without OAuth, applications would need:

  • Direct access to user credentials

  • Full access to all resources

  • No way to revoke access without changing passwords

OAuth provides:

  • Delegated authorization (no password sharing)

  • Scoped access (limited permissions)

  • Revocable tokens (easy access removal)

Key Concepts

Roles

Role
Description

Resource Owner

The user who owns the data

Client

The application requesting access

Authorization Server

Issues tokens after authorization

Resource Server

Hosts the protected resources (API)

Tokens

Token
Purpose
Lifetime

Authorization Code

Exchanged for tokens

Minutes

Access Token

Authorizes API requests

Hours

Refresh Token

Gets new access tokens

Days/Weeks

Scopes

Scopes define what access is granted:

Clients request scopes:

Users consent to scopes:

Grant Types

Authorization Code (Most Common)

Best for: Web applications with a backend

The client never sees the user's password.

Authorization Code + PKCE

Best for: Mobile apps, single-page applications

Same as authorization code, but with proof key:

  1. Client generates random code_verifier

  2. Client sends code_challenge = SHA256(code_verifier)

  3. Authority returns code

  4. Client proves identity with code_verifier

Client Credentials

Best for: Machine-to-machine

No user involved - the service itself is authorized.

Device Code

Best for: TVs, CLI tools, IoT

The Authorization Flow

Step by Step

  1. User wants to access protected resource

    User clicks "Login with Authority" in your app.

  2. Client redirects to Authorization Server

  3. User authenticates

    Authority shows login page. User enters credentials.

  4. User authorizes

    Authority shows consent screen. User approves scopes.

  5. Authorization Server redirects back

  6. Client exchanges code for tokens

  7. Client receives tokens

  8. Client uses access token

Security Concepts

State Parameter

Prevents CSRF attacks:

  1. Client generates random state

  2. Client stores state in session

  3. Client includes state in authorization request

  4. Authority returns state in callback

  5. Client verifies state matches

PKCE

Prevents authorization code interception:

Token Security

  • Short-lived access tokens - Limit exposure window

  • Token rotation - New refresh token each use

  • Secure storage - Never store in URL or logs

Common Misconceptions

"OAuth is for authentication"

OAuth is for authorization (what you can do), not authentication (who you are). OpenID Connect adds authentication.

"The access token contains user data"

Access tokens authorize access - they don't necessarily contain user info. Use the UserInfo endpoint or ID tokens for identity.

"Longer token lifetimes are more secure"

Shorter lifetimes with refresh tokens are more secure. If a token is compromised, the damage window is limited.

Next Steps

Last updated

Was this helpful?