How Authentication Works
This page explains how Aero2 authenticates users at a high level. Aero2 implements the industry-standard OAuth 2.0 and OpenID Connect (OIDC) protocols, so your application never handles passwords directly.
The Authorization Code Flow
The primary way users authenticate with Aero2 is through the Authorization Code flow with PKCE:
- Your application redirects the user to Aero2's authorization endpoint.
- The user authenticates (enters credentials, uses social login, etc.).
- Aero2 redirects back to your application with an authorization code.
- Your application exchanges the code for tokens (access token, ID token, refresh token).
- Your application uses the access token to make authenticated API calls.
- 1Browser → Your AppUser clicks Login
- 2Your AppGenerate PKCE code_verifier + code_challengecrypto.getRandomValues() + SHA-256
- 3Your App → Aero2Redirect to /oauth2/authorize?client_id=...&redirect_uri=...&code_challenge=...&code_challenge_method=S256&response_type=code&scope=openid+profile+email
- 4Aero2 → BrowserShow login pageUser authenticates with identity provider
- 5Aero2 → Your AppRedirect to redirect_uri with code?code=abc123&state=xyz
- 6Your App → Aero2Exchange code for tokensPOST /oauth2/token grant_type=authorization_code&code=...&code_verifier=...
- 7Aero2 → Your AppReturn access_token, id_token, refresh_tokenRS256-signed JWTs
- 8Your App → Aero2Fetch user info (optional)GET /oauth2/userinfo Authorization: Bearer <access_token>
PKCE (Proof Key for Code Exchange) is required for all authorization requests. It protects the flow from code interception attacks by binding the token exchange to the original authorization request.
The Relying Party Flow (Social Login)
When a user chooses to sign in with an external provider like GitHub or Google, Aero2 acts as a relying party — it delegates authentication to the external provider:
- The user clicks "Sign in with GitHub" in your application.
- Your application redirects to Aero2, which redirects to GitHub.
- The user authenticates with GitHub.
- GitHub redirects back to Aero2 with the user's identity.
- Aero2 creates or links a local user account and establishes a session.
- Aero2 redirects back to your application with an authorization code.
- Your application exchanges the code for tokens, just like the standard flow.
- 1Browser → Aero2User clicks Login with GitHubGET /rp/authorize?idp=github&redirect_uri=/dashboard
- 2Aero2Generate state, store in DB10-minute expiry, set HttpOnly cookie
- 3Aero2 → External IdPRedirect to GitHub authorize URL?client_id=...&redirect_uri=/rp/callback/github&state=...
- 4External IdP → BrowserUser authenticates with GitHub
- 5External IdP → Aero2Redirect back with codeGET /rp/callback/github?code=...&state=...
- 6Aero2Validate state (cookie + DB)Atomic DELETE with RETURNING prevents replay
- 7Aero2 → External IdPExchange code for access tokenPOST to GitHub token endpoint
- 8Aero2 → External IdPFetch user info from GitHubGET /user with access token
- 9Aero2Create/link local user, create session
- 10Aero2 → BrowserSet session cookie, redirect to dashboardHttpOnly, Secure, SameSite=Lax
From your application's perspective, the flow is the same regardless of whether the user signs in with a password or a social provider. Aero2 handles all the provider-specific logic.
Tokens
Aero2 issues several types of JWT tokens:
- Access tokens — Short-lived tokens used to authenticate API requests. Verified using the JWKS endpoint.
- ID tokens — Contain user identity claims (name, email). Used by your frontend to display user info.
- Refresh tokens — Long-lived tokens used to obtain new access tokens without re-authentication. Subject to rotation.
All tokens are signed with RS256 and can be verified using the public keys available at the JWKS endpoint.
What's Next?
- Add Auth to a React App — Step-by-step integration guide
- Protect an API — Server-side token verification
- Social Login — Set up GitHub, Google, or custom providers
- Tokens concept — Deep dive into token types and verification
- Authorization Code + PKCE — Detailed flow walkthrough