1.0.4 • Published 4 months ago

authify-pro v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Authify-Pro

A flexible authentication package for Node.js applications that provides multiple authentication methods including email/password, OAuth (Google, GitHub, Microsoft), and SSO integration.

Features

  • 🔐 Multiple Authentication Methods:

    • Email/Password Authentication
    • OAuth Support (Google, GitHub, Microsoft)
    • SSO Integration
    • Security Questions Option
    • OTP Verification
  • 📧 Email Features:

    • Customizable Email Templates
    • OTP Delivery
    • HTML Email Support
    • Custom SMTP Configuration
  • 🔒 Security:

    • JWT Token Based Authentication
    • Multiple Hashing Algorithms
    • Password Strength Validation
    • Rate Limiting Support
  • 🛠️ Customization:

    • Configurable Token Expiry
    • Custom Email Templates
    • Flexible OAuth Settings
    • Custom Security Questions

Installation

npm install authify-pro

Quick Start

import express from 'express';
import AuthenticationPackage from 'authify-pro';

const app = express();

const authPackage = new AuthenticationPackage({
  mongoURI: 'your-mongodb-uri',
  jwtSecret: 'your-jwt-secret',
  emailConfig: {
    service: 'gmail',
    auth: {
      user: 'your-email@gmail.com',
      pass: 'your-password'
    }
  }
});

// Use the authentication routes
app.use(authPackage.getRouter());

Configuration Options

interface IAuthConfig {
  // Required
  mongoURI: string;
  jwtSecret: string;

  // Optional
  baseUrl?: string;
  verificationMethod?: 'email' | 'security_question' | 'none';
  sessionDuration?: string;

  // Email Configuration
  emailConfig?: {
    service: string;
    auth: {
      user: string;
      pass: string;
    };
    templateConfig?: {
      companyName?: string;
      brandColor?: string;
      supportEmail?: string;
    }
  };

  // OAuth Configuration
  oauth?: {
    google?: {
      clientId: string;
      clientSecret: string;
    };
    github?: {
      clientId: string;
      clientSecret: string;
    };
    microsoft?: {
      clientId: string;
      clientSecret: string;
    }
  };
}

Usage Examples

Basic Email/Password Authentication

const authPackage = new AuthenticationPackage({
  mongoURI: 'mongodb://localhost:27017/your-db',
  jwtSecret: 'your-secret-key',
  verificationMethod: 'email'
});

OAuth Integration

const authPackage = new AuthenticationPackage({
  mongoURI: 'mongodb://localhost:27017/your-db',
  jwtSecret: 'your-secret-key',
  oauth: {
    google: {
      clientId: 'your-google-client-id',
      clientSecret: 'your-google-client-secret'
    },
    github: {
      clientId: 'your-github-client-id',
      clientSecret: 'your-github-client-secret'
    }
  }
});

Custom Email Template

const authPackage = new AuthenticationPackage({
  // ... other config
  emailConfig: {
    service: 'gmail',
    auth: {
      user: 'your-email@gmail.com',
      pass: 'your-password'
    },
    templateConfig: {
      companyName: 'Your Company',
      brandColor: '#007bff',
      supportEmail: 'support@yourcompany.com'
    }
  }
});

Available Routes

Authentication Routes

  • POST /auth/signup - Register new user
  • POST /auth/login - Login
  • POST /auth/verify - Verify OTP
  • GET /auth/logout - Logout

OAuth Routes

  • GET /auth/google - Google OAuth
  • GET /auth/github - GitHub OAuth
  • GET /auth/microsoft - Microsoft OAuth

SSO Routes

  • GET /login - SSO Login
  • GET /callback - SSO Callback
  • GET /logout - SSO Logout

Security

The package includes several security features:

  • Password hashing using multiple algorithms
  • JWT token encryption
  • Rate limiting capabilities
  • CORS support
  • XSS protection
  • Secure cookie options

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the ISC License.

Support

For support, please raise an issue in the GitHub repository or contact vishvam3001@gmail.com .

Author

Vishvam Amin