Skip to content

Debanjan2007/uniauth

Repository files navigation

Uniauth Banner

Uniauth 🔐

Unified OAuth authentication toolkit for modern JavaScript applications.

OAuth providers should not require different code paths.

Uniauth Logo

OAuth made less painful.


✨ What is Uniauth?

Uniauth is a TypeScript-first OAuth wrapper library for social login providers.

It provides a unified provider interface so you can integrate multiple OAuth providers without rewriting authentication logic for every platform.

The goal is simple:

  • unified OAuth flows
  • reusable provider architecture
  • PKCE-ready utilities
  • scalable provider expansion
  • developer-friendly API surface

Why Uniauth?

Most OAuth libraries force developers into:

  • provider-specific logic
  • inconsistent APIs
  • unnecessary boilerplate
  • framework lock-in

Uniauth provides:

  • a unified provider interface
  • consistent OAuth flow handling
  • TypeScript-first developer experience
  • lightweight and flexible architecture

Write authentication logic once and switch providers easily.


✨ Features

  • 🔐 Unified OAuth API
  • ⚡ Lightweight architecture
  • 🧠 TypeScript-first developer experience
  • 🔄 Consistent provider flow handling
  • 🛠 Framework agnostic
  • 📦 Easy provider integration
  • 🚀 Minimal setup
  • 🔑 PKCE-ready utilities
  • 🌱 Scalable provider system

⚖️ Comparison

Feature Uniauth Passport.js
Unified provider API
TypeScript-first ⚠️ Partial
Lightweight setup
Consistent flow handling
Minimal boilerplate
Framework agnostic ⚠️
PKCE utilities included

📦 Installation

Package currently published under the @deba_1307 scope.

npm

npm install @deba_1307/uniauth

pnpm

pnpm add @deba_1307/uniauth

yarn

yarn add @deba_1307/uniauth

📋 Requirements

Before using Uniauth, make sure your environment meets the following requirements:

  • Node.js >= 20
  • npm, pnpm, or yarn

Check your current Node.js version:

node -v

🚀 Quick Start

import Uniauth from '@deba_1307/uniauth'

const auth = new Uniauth({
  providers: {
    Google: {
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      redirecturl: 'http://localhost:3000/auth/google/callback',
      scope: ['openid', 'email', 'profile']
    }
  }
})

const google = auth.getProvider('Google')

const url = google.getAuthorizationUrl()

🚀 Google OAuth + PKCE Flow

Google provider uses the PKCE OAuth flow.

The overall provider usage remains identical to other providers, but there is one additional step.

You must extract and store the generated PKCE key and the Authurl from the authorization URL using the Extractkey() helper.

That extracted key is later required during token exchange.

Google Example

import Uniauth from '@deba_1307/uniauth'
import { Extractkey } from '@deba_1307/uniauth'

const auth = new Uniauth({
  providers: {
    Google: {
      clientId: '<YOUR_GOOGLE_CLIENT_ID>',
      clientSecret: '<YOUR_GOOGLE_CLIENT_SECRET>',
      redirecturl: 'https://yourapp.com/auth/google/callback',
      scope: ['openid', 'email', 'profile']
    }
  }
})

const google = auth.getProvider('Google')

/* ⚠️Don't use ❌ this 'url' as you authorization url

it might return a invalid redirect_uri issue

⚠️ */

const url = google.getAuthorizationUrl()

/*
  Extract the generated PKCE key.

  Store this key securely because it will be
  required later during token exchange.
*/

const { key, AuthUrl } = Extractkey(url)

// redirect user to AuthUrl

// after OAuth callback:
const token = await google.exchangeCodeForToken(code, key)

// fetch user profile
const profile = await google.getUserProfile(token.accessToken)

🚀 LinkedIn OAuth Example

import Uniauth from '@deba_1307/uniauth'

const auth = new Uniauth({
  providers: {
    Linkedin: {
      clientId: '<YOUR_LINKEDIN_CLIENT_ID>',
      clientSecret: '<YOUR_LINKEDIN_CLIENT_SECRET>',
      redirecturl: 'https://yourapp.com/auth/linkedin/callback',
      scope: ['r_liteprofile', 'r_emailaddress']
    }
  }
})

const linkedin = auth.getProvider('Linkedin')

const authorizationUrl = linkedin.getAuthorizationUrl()

// redirect user to authorizationUrl

// after callback, exchange the authorization code:
const token = await linkedin.exchangeCodeForToken(code)

// fetch the LinkedIn user profile:
const profile = await linkedin.getUserProfile(token.accessToken)

🔧 Provider Configuration

Every OAuth provider accepts the following configuration:

  • clientId — provider application client ID
  • clientSecret — provider application client secret
  • redirecturl — OAuth callback redirect URI
  • scope — array of OAuth scopes

Example:

{
  clientId: 'abc123',
  clientSecret: 'secret',
  redirecturl: 'https://yourapp.com/auth/provider/callback',
  scope: ['openid', 'profile']
}

🧠 Authentication Architecture

Your Application
       ↓
    Uniauth
       ↓
OAuth Providers
(Google, LinkedIn, GitHub...)

Uniauth abstracts provider-specific OAuth logic into a unified developer-friendly API.


🚧 Current Status

Uniauth is under active development and new providers/features are being added continuously.

Implemented

  • LinkedIn OAuth provider
  • Google OAuth provider
  • Authorization URL generation
  • Access token exchange flow
  • User profile fetching
  • PKCE utility helpers
  • ESM + CommonJS builds
  • CI workflow integration

Planned

  • GitHub OAuth
  • Discord OAuth
  • Spotify OAuth
  • Twitter/X OAuth
  • Facebook OAuth
  • Session helpers
  • Adapter ecosystem

🗺️ Roadmap

  • LinkedIn OAuth
  • Google OAuth
  • PKCE utilities
  • ESM + CommonJS support
  • GitHub OAuth
  • Discord OAuth
  • Spotify OAuth
  • Session utilities
  • Provider adapters
  • Framework integrations
  • Better developer tooling

🧠 API Notes

  • Uniauth currently exposes a default class
  • getProvider(providerName) returns the provider instance
  • Providers expose:
    • getAuthorizationUrl()
    • exchangeCodeForToken(code)
    • getUserProfile(accessToken)

📁 Library Structure

  • src/index.ts — library entrypoint
  • src/providers/core/Uniauth.ts — provider registry and configuration
  • src/providers/linkedin/LinkedinProvider.ts — LinkedIn OAuth implementation
  • src/providers/linkedin/Linkedin.types.ts — LinkedIn provider types
  • src/providers/core/types/TokenResponse.types.ts — token response shape
  • src/providers/core/types/UserProfile.types.ts — user profile shape
  • src/pkce/* — PKCE helper utilities

🛠 Notes

  • Automated tests and CI validation are included
  • The provider system is designed for scalable expansion
  • Additional providers can be added by extending the provider core architecture

🤝 Contributing

Contributions are welcome.

If you want to add a provider:

  1. Create a provider class under src/providers
  2. Add the required provider types
  3. Register the provider inside src/providers/core/Uniauth.ts

Issues, discussions, and pull requests are always appreciated.


📄 License

MIT

About

A wrapper on different social media oauth 2.0

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors