🛣️ OAuth Route Blocks
OAuth route blocks provide pre-configured HTTP endpoints for third-party OAuth flows in NodeBlocks applications. These routes compose blocks, logging, and error handling to deliver a robust OAuth experience. The initial provider is Google; additional providers will follow the same patterns.
🎯 Overview
OAuth route blocks are designed to:
- Expose OAuth endpoints for initiation and callback processing
- Compose handlers with logging for observability
- Centralize error handling with consistent HTTP status mapping
- Leverage schema validation for query parameters
📋 Route Structure
Each OAuth route follows a consistent pattern:
- HTTP Method: Operation type (GET)
- Path: Endpoint URL
- Blocks: Composed function chain for OAuth flow orchestration
- Validators: Authentication and authorization checks (none for OAuth routes)
🔧 Available OAuth Routes
googleOAuthRoute
Initiates Google OAuth authentication flow via GET /auth/oauth/google
.
Purpose: Starts the Google OAuth flow by delegating to the OAuth driver and preparing state.
Route Details:
- Method:
GET
- Path:
/auth/oauth/google
- Authentication: Not required
Blocks:
requestGoogleOAuth
- Initiates Google OAuth flow and generates signed state
Validators: None (validation handled by schema)
Usage:
import { compose } from '@nodeblocks/backend-sdk';
// Use in feature composition:
export const googleOAuthFeature = compose(googleOauthSchema, googleOAuthRoute);
googleOAuthCallbackRoute
Processes Google OAuth callback and redirects the user via GET /auth/oauth/google/callback
.
Purpose: Completes the OAuth flow by authenticating the provider callback, verifying login state, issuing tokens, and redirecting the user.
Route Details:
- Method:
GET
- Path:
/auth/oauth/google/callback
- Authentication: Not required
Blocks:
authenticateGoogleOAuth
- Validates provider callback and reads user profileextractOAuthLoginState
- Extracts and validates OAuth login state from encrypted tokenverifyGoogleOAuth
- Resolves or creates identity based on provider profilegenerateRedirectURL
- Generates signed redirect URL with tokenredirectTo
- Issues HTTP redirect to the client
Validators: None (validation handled by schema)
Usage:
import { compose } from '@nodeblocks/backend-sdk';
// Use in feature composition:
export const googleOAuthCallbackFeature = compose(
googleOauthCallbackSchema,
googleOAuthCallbackRoute
);