ใƒกใ‚คใƒณใ‚ณใƒณใƒ†ใƒณใƒ„ใพใงใ‚นใ‚ญใƒƒใƒ—
ใƒใƒผใ‚ธใƒงใƒณ: 0.6.0 (Latest)

๐Ÿ”— 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