First OAuth Integration

Build a complete OAuth 2.0 integration from scratch. You'll implement the authorization code flow with PKCE.

Prerequisites

  • Completed Quick Start

  • Authority running on http://localhost:4000

  • An OAuth client created with:

    • Redirect URI: http://localhost:3000/callback

What You'll Build

A simple web application that:

  1. Redirects users to Authority for authentication

  2. Receives an authorization code

  3. Exchanges the code for access tokens

  4. Uses tokens to access protected resources

The Authorization Code Flow

spinner

Step 1: Generate PKCE Values

PKCE protects against authorization code interception. Generate a code verifier and challenge:

Step 2: Redirect to Authorization Endpoint

Build the authorization URL and redirect the user:

Step 3: Handle the Callback

After the user authenticates, Authority redirects to your callback URL:

Step 4: Exchange Code for Tokens

Make a POST request to the token endpoint:

The response contains:

Step 5: Use the Access Token

Include the token in API requests:

Complete Example

Here's a minimal HTML page implementing the full flow:

Next Steps

Last updated

Was this helpful?