Saikat
Back to npm packages

social-auth-unifier

v0.0.2

Unified Social Auth Package for Google, Twitter, Facebook, LinkedIn, and GitHub

16 / monthMIT LicenseUpdated December 5, 2025

social-auth-unifier

Passport strategies for authenticating with Google, Twitter, Facebook, LinkedIn, and GitHub using OAuth 2.0, all unifed in a single NestJS module.

This module lets you authenticate using multiple social providers in your Node.js applications. By plugging into Passport, social authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express and NestJS.

Install

$ npm install social-auth-unifier

Usage

Configure Strategy

The unified strategy authenticates users using a client ID and client secret, which are obtained by creating an application at the respective developer portals (e.g., Google Cloud Console, Twitter Developer Portal). The client ID and secret are supplied as environment variables.

import { Module } from '@nestjs/common';
import { SocialAuthModule } from 'social-auth-unifier';

@Module({
  imports: [
    // Register the module. It will automatically read from process.env
    SocialAuthModule.register(),
  ],
})
export class AppModule {}

Environment Variables

The module automatically detects and configures enabled providers based on the presence of these environment variables:

# Google
GOOGLE_AUTH=true
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/redirect

# Twitter
TWITTER_AUTH=true
TWITTER_CLIENT_ID=your-twitter-client-id
TWITTER_CLIENT_SECRET=your-twitter-client-secret
TWITTER_CALLBACK_URL=http://localhost:3000/auth/twitter/redirect

# Facebook
FACEBOOK_AUTH=true
FACEBOOK_CLIENT_ID=your-facebook-client-id
FACEBOOK_CLIENT_SECRET=your-facebook-client-secret
FACEBOOK_CALLBACK_URL=http://localhost:3000/auth/facebook/redirect

# LinkedIn
LINKEDIN_AUTH=true
LINKEDIN_CLIENT_ID=your-linkedin-client-id
LINKEDIN_CLIENT_SECRET=your-linkedin-client-secret
LINKEDIN_CALLBACK_URL=http://localhost:3000/auth/linkedin/redirect

# GitHub
GITHUB_AUTH=true
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
GITHUB_CALLBACK_URL=http://localhost:3000/auth/github/redirect

Authenticate Requests

Use the built-in routes to initiate authentication. The module automatically registers controllers for enabled strategies.

  • Google: GET /auth/google
  • Twitter: GET /auth/twitter
  • Facebook: GET /auth/facebook
  • LinkedIn: GET /auth/linkedin
  • GitHub: GET /auth/github

For example, to log in with GitHub, simply link to:

<a href="/auth/github">Login with GitHub</a>

License

MIT

Author

Repository