|$ curl https://forge-ai.dev/api/markdown?path=docs/security/oauth2
$cat docs/oauth-2.0.md
updated Recently·24 min read·published

OAuth 2.0

SecurityOAuthOIDCAuthIntermediate🎯Free Tools
Introduction

OAuth 2.0 is an authorization framework that lets users grant third-party applications limited access to their resources without sharing passwords. OpenID Connect (OIDC) builds on OAuth 2.0 to add authentication (identity).

Roles
RoleDescription
Resource OwnerThe user who owns the data
ClientThe application requesting access
Authorization ServerIssues tokens after authenticating the user
Resource ServerHosts the protected APIs
Authorization Code Flow
auth-code-flow.txt
TEXT
11. User clicks "Sign in with Provider" in the client app.
22. Client redirects browser to the authorization server.
33. User logs in and consents to requested scopes.
44. Authorization server redirects back with an authorization code.
55. Client exchanges the code for access and refresh tokens.
66. Client uses the access token to call APIs on behalf of the user.
PKCE

Proof Key for Code Exchange (PKCE) protects public clients (mobile apps, SPAs) from authorization code interception. The client generates a secret verifier, sends a hashed challenge, and later proves possession of the verifier during token exchange.

best practice

Always use PKCE for mobile and single-page apps. Modern OAuth 2.1 makes PKCE mandatory for all clients.
Tokens
TokenPurposeLifetime
Access TokenAuthorize API requestsShort (minutes to hours)
Refresh TokenObtain new access tokensLong (days to months)
ID TokenProve user identity (OIDC)Short
Security Considerations
  • Use HTTPS everywhere.
  • Store tokens securely; never expose refresh tokens in browsers.
  • Validate state parameter to prevent CSRF.
  • Use exact redirect URI matching.
  • Request the minimum scopes necessary.