1.0.9 • Published 5 months ago

authify-pro2 v1.0.9

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

Authify-Pro2

Authify-Pro2 is a comprehensive authentication package for Node.js applications. It provides a set of robust and secure authentication functionalities, including basic authentication, OTP-based authentication, and social authentication with popular platforms like GitHub, Google, Microsoft, and Okta.

Features

  • Basic authentication with secure password hashing
  • OTP (One-Time Password) generation and verification
  • Social authentication with GitHub, Google, Microsoft, and Okta
  • JWT (JSON Web Token) generation and validation
  • Customizable and extensible architecture
  • Easy integration with Express.js applications
  • TypeScript support for enhanced type safety and development experience

Installation

To install Authify-Pro2, use npm:

npm install authify-pro2

Usage

Basic Authentication

import { authBasic } from 'authify-pro2';

// Authenticate user credentials
const isAuthenticated = authBasic.authenticate(enteredPassword, storedPassword, saltValue);

OTP Authentication

import { authOTP } from 'authify-pro2';

// Generate and send OTP
const generatedOTP = await authOTP.generateAndSendOTP(emailAddress);

// Validate OTP
const isValid = authOTP.validateOTP(emailAddress, providedOTP);

Social Authentication

import { authenticateWithOAuth2 } from 'authify-pro2';

// Configuration for extracting user profile
const config = {
  getUserProfile: (profile: any) => ({
    name: profile.name,
    email: profile.email,
    // ...
  }),
};

// Authenticate with OAuth2 provider
const { userProfile, accessTokenValue } = await authenticateWithOAuth2(code, config, providerName);

JWT Tokens

import { tokenHelper } from 'authify-pro2';

// Generate JWT token
const token = tokenHelper.createToken(payload, expiresInSeconds);

// Validate JWT token
const decodedToken = tokenHelper.validateToken(token);

Hashing and Validation

import { hashHelper, validationHelper } from 'authify-pro2';

// Generate salt
const salt = hashHelper.generateSalt();

// Generate hash
const hashedValue = hashHelper.generateHash(inputValue, salt);

// Validate hash
const isValid = hashHelper.validateHash(inputValue, hashValue, salt);

// Validate email
const isValidEmail = validationHelper.isValidEmail(emailAddress);

// Validate password
const isValidPassword = validationHelper.isValidPassword(password);

Configuration

Authify-Pro2 requires the following environment variables to be set:

  • HASH_ALGORITHM: The hashing algorithm to use for password hashing (e.g., 'sha256', 'sha512').
  • JWT_SIGNING_KEY: The secret key used for signing and verifying JWT tokens.

Additionally, for social authentication, you need to provide the necessary configuration for each provider:

  • GITHUB_CLIENT_ID: Client ID for GitHub OAuth2 authentication.
  • GITHUB_CLIENT_SECRET: Client secret for GitHub OAuth2 authentication.
  • GITHUB_REDIRECT_URI: Redirect URI for GitHub OAuth2 authentication.
  • GITHUB_TOKEN_URL: Token URL for GitHub OAuth2 authentication.
  • GITHUB_USER_INFO_URL: User info URL for GitHub OAuth2 authentication.

Similar configuration variables are required for Google, Microsoft, and Okta authentication.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

License

This package is open-source and available under the MIT License.

Support

For any questions or support regarding Authify-Pro2, please contact us at support@authify-pro2.com.

Happy authenticating with Authify-Pro2!

Authify-Pro2

Authify-Pro2 is a comprehensive authentication package for Node.js applications. It provides a set of robust and secure authentication functionalities, including basic authentication, OTP-based authentication, social authentication with popular platforms like GitHub, Google, Microsoft, and Okta, and database integration using TypeORM.

Features

  • Basic authentication with secure password hashing
  • OTP (One-Time Password) generation and verification
  • Social authentication with GitHub, Google, Microsoft, and Okta
  • JWT (JSON Web Token) generation and validation
  • Database integration with TypeORM (supports MySQL, PostgreSQL, and MongoDB)
  • Automatic schema synchronization
  • Customizable and extensible architecture
  • Easy integration with Express.js applications
  • TypeScript support for enhanced type safety and development experience

Installation

To install Authify-Pro2, use npm:

npm install authify-pro2

Usage

Database Integration

Initialize the authentication service with your database configuration:

import { AuthifyService } from 'authify-pro2';

const authify = new AuthifyService({
  type: 'mysql', // or 'postgres' or 'mongodb'
  url: 'mysql://user:password@localhost:3306/dbname',
  synchronize: true // WARNING: Only use in development
});

await authify.initialize();

Basic Authentication

// Create a new user
await authify.createUser('user@example.com', 'password123');

// Validate credentials
const isValid = await authify.validateCredentials('user@example.com', 'password123');

OTP Authentication

// Generate and send OTP
const otp = await authify.generateAndSendOTP('user@example.com');

// Validate OTP
const isValid = await authify.validateOTP('user@example.com', providedOTP);

Social Authentication

// Configuration for extracting user profile
const config = {
  getUserProfile: (profile: any) => ({
    name: profile.name,
    email: profile.email,
    // ...
  }),
};

// Authenticate with OAuth2 provider
const result = await authify.handleOAuth2(code, config, 'github');

Direct Authentication Methods

You can also use the core authentication methods without database integration:

import { authBasic, authOTP, authenticateWithOAuth2, tokenHelper } from 'authify-pro2';

// Basic authentication
const isAuthenticated = authBasic.authenticate(enteredPassword, storedPassword, saltValue);

// Generate JWT token
const token = tokenHelper.createToken(payload, expiresInSeconds);

Configuration

Environment Variables

Authify-Pro2 requires the following environment variables:

Core Authentication:

  • HASH_ALGORITHM: The hashing algorithm for password hashing (e.g., 'sha256')
  • JWT_SIGNING_KEY: Secret key for JWT tokens

OAuth Providers:

  • GITHUB_CLIENT_ID: GitHub OAuth2 client ID
  • GITHUB_CLIENT_SECRET: GitHub OAuth2 client secret
  • GITHUB_REDIRECT_URI: GitHub OAuth2 redirect URI
  • GITHUB_TOKEN_URL: GitHub OAuth2 token URL
  • GITHUB_USER_INFO_URL: GitHub OAuth2 user info URL

(Similar variables needed for Google, Microsoft, and Okta)

Database Schema

When using database integration, Authify-Pro2 automatically creates the following tables:

  • users: Stores user information and credentials
  • auth_records: Stores OTP and session records
  • oauth_connections: Stores OAuth provider connections

TypeORM Integration

Supported Databases

  • MySQL/MariaDB
  • PostgreSQL
  • MongoDB

Schema Synchronization

The package supports automatic schema synchronization using TypeORM's synchronize option. Note: This should only be used during development.

const authify = new AuthifyService({
  type: 'mysql',
  url: 'mysql://user:password@localhost:3306/dbname',
  synchronize: true, // Development only
  logging: true // Optional: enables SQL query logging
});

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.

License

This package is open-source and available under the MIT License.

Support

For any questions or support regarding Authify-Pro2, please contact us at support@authify-pro2.com.

Happy authenticating with Authify-Pro2!

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago