メインコンテンツまでスキップ
バージョン: 🚧 Canary

🔗 OAuth Feature Blocks

OAuth feature blocks provide complete, pre-composed functionality for OAuth authentication flows. These features combine schemas and routes to create ready-to-use endpoints for OAuth initiation and callback processing.


🎯 Overview

OAuth feature blocks are designed to:

  • Provide complete OAuth workflows for provider-based login
  • Combine schemas with routes for validated request processing
  • Integrate with drivers/blocks to orchestrate the full OAuth flow

📋 Feature Structure

Each OAuth feature follows a consistent composition pattern:

  • Schema: Validates input data and parameters
  • Route: Provides HTTP endpoint with block composition
  • Composition: Combines schema and route using compose

🔧 Available OAuth Features

googleOAuthFeature

Google OAuth authentication feature with schema validation and routing.

Purpose: Starts the Google OAuth flow and redirects to provider consent.

Composition:

  • Schema: googleOauthSchema — validates query parameters (fp, purpose, redirectUrl, typeId) and enforces empty request body
  • Route: googleOAuthRoute — handles Google OAuth initiation

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database (handlers may need dataStores):
app.use('/api', defService(partial(features.googleOAuthFeature, [{ dataStores: db }])));

API Endpoint: GET /api/auth/oauth/google


googleOAuthCallbackFeature

Google OAuth callback feature with routing for callback processing.

Purpose: Completes the OAuth flow by authenticating the provider callback, verifying login state, and performing final redirect.

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database (handlers may need dataStores):
app.use('/api', defService(partial(features.googleOAuthCallbackFeature, [{ dataStores: db }])));

API Endpoint: GET /api/auth/oauth/google/callback


twitterOAuthFeature

Twitter OAuth authentication feature with schema validation and routing.

Purpose: Starts the Twitter OAuth flow and redirects to provider consent.

Composition:

  • Schema: twitterOauthSchema — validates query parameters (purpose, redirectUrl, typeId) and enforces empty request body
  • Route: twitterOAuthRoute — handles Twitter OAuth initiation

Usage:

import { features } from '@nodeblocks/backend-sdk';

// With database (handlers may need dataStores):
app.use('/api', defService(partial(features.twitterOAuthFeature, [{ dataStores: db }])));

API Endpoint: GET /api/auth/oauth/twitter


twitterOAuthCallbackFeature

Twitter OAuth callback feature with routing for callback processing.

Purpose: Completes the OAuth flow by authenticating the provider callback, verifying user, and performing final redirect.

Composition:

  • Route: twitterOAuthCallbackRoute — handles Twitter OAuth callback verification and user processing

Usage:

import { features } from '@nodeblocks/backend-sdk';

// With database (handlers may need dataStores):
app.use('/api', defService(partial(features.twitterOAuthCallbackFeature, [{ dataStores: db }])));

API Endpoint: GET /api/auth/oauth/twitter/callback