🔐 OAuth Drivers
OAuth drivers provide a consistent integration layer for third-party OAuth providers using Passport.js. They encapsulate provider strategy setup and expose simple request and callback helpers you can compose into routes and features.
🎯 Overview
OAuth drivers in NodeBlocks are thin wrappers around Passport.js strategies that provide:
- Strategy setup with provider credentials and scopes
- Promise-based request/callback helpers for composition
- Pluggable verification callbacks to normalize provider profiles
📋 Available OAuth Drivers
Google OAuth Driver
The Google OAuth driver integrates Passport.js Google strategy and exposes helpers for request and callback handling.
verifyGoogleCallback
Verifies Google OAuth callback and processes user profile data for Passport.js authentication.
Purpose: Extract a normalized profile (email, displayName, accessToken) and pass it to Passport.
Parameters:
_req: Request
— Express request object (unused in this implementation)accessToken: string
— Google OAuth access token for API accessrefreshToken: string
— Google OAuth refresh token for token renewalprofile: Profile
— Google user profile data from OAuth callbackdone: VerifyCallback
— Passport.js verification callback function
Returns: void
— Calls done callback with result or error
Handler Process:
- Input: Request, access/refresh tokens, Google profile, Passport callback
- Process: Extracts email from profile, validates presence, formats
{ accessToken, displayName, email }
- Output: Calls
done(null, formattedProfile)
ordone(error, false)
- Errors: Throws
AuthenticationBadRequestError
when email is missing
Usage:
passport.use(new GoogleStrategy({ verifyGoogleCallback }));
createGoogleOAuthDriver
Creates Google OAuth driver with Passport.js strategy and authentication helpers.
Purpose: Configure Google strategy and expose initialize
, request
, and callback
helpers.
Parameters:
clientID: string
— Google OAuth client ID from Google Cloud ConsoleclientSecret: string
— Google OAuth client secret from Google Cloud ConsolecallbackURL: string
— URL where Google will redirect after OAuth completionscope: string[]
— Array of OAuth scopes to request (defaults to['email', 'profile']
)verify: typeof verifyGoogleCallback
— Optional verification function (defaults toverifyGoogleCallback
)
Returns: GoogleOAuthDriver
— GoogleOAuthDriver object with complete OAuth flow management
Handler Process:
- Input: Client credentials, callback URL, scopes, verification function
- Process: Configures Passport Google strategy; wraps
passport.authenticate
in Promises for request/callback - Output: Driver object exposing
initialize
,request
, andcallback
- Errors: Propagates Passport/Promise rejections
Usage:
// Create Google OAuth driver:
const googleDriver = createGoogleOAuthDriver(
'your-client-id',
'your-client-secret',
'https://app.com/auth/google/callback'
);
// Use in Express app:
app.use('/auth/google', googleDriver.initialize);
🔗 Related Documentation
- OAuth Blocks — Business logic for OAuth flows
- OAuth Routes — HTTP route compositions for OAuth