1.6.5 • Published 5 months ago

auth-it v1.6.5

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

auth-it

A comprehensive authentication package providing:

OAuth authentication with Google, GitHub, Microsoft, and Okta.
JWT token generation and verification.
Secure password hashing.
OTP (One-Time Password) functionality.

This package is designed to be easy to integrate into your application, providing flexible and secure user authentication.


📑 Table of Contents


🚀 Features

FeatureDescription
🔐 JWT AuthenticationSecurely sign and verify JSON Web Tokens.
🔑 OAuth AuthenticationIntegrate authentication with Google, GitHub, Microsoft, and Okta.
🔏 Password HashingSafely hash and validate user passwords using SHA-512.
🔢 OTP AuthenticationGenerate and verify OTPs for added security.

📥 Installation

Using npm:

npm install auth-it

Using yarn:

yarn add auth-it

⚙️ Environment Variables

To use the package, configure the following environment variables in your .env file.

# For Okta
OKTA_ISSUER=https://your-okta-domain.okta.com/oauth2/default
OKTA_CLIENT_ID=your-okta-client-id
OKTA_CLIENT_SECRET=your-okta-client-secret
OKTA_REDIRECT_URI=http://localhost:3000/callback

# For Microsoft
TENANT_ID=your-microsoft-tenant-id

# JWT Secret Key
JWT_SECRET_KEY=your-jwt-secret-key

Replace placeholder values with your actual credentials.


📌 Usage

To use this package, import the required authentication service as shown below:

1️⃣ Basic Authentication (Hash Service)

import { hashService } from 'auth-it';

// Create Salt
const salt = hashService.createSalt();
console.log(salt);

// Hash Password
const hashedPassword = hashService.hashPassword('userPassword', salt);
console.log(hashedPassword);

// Validate Password
const isValid = hashService.validatePassword('userPassword', salt, hashedPassword);
console.log(isValid); // true or false

// Generate JWT Token
const token = hashService.generateJwt({ userId: '123' });
console.log(token);

// Verify JWT Token
const decoded = hashService.verifyToken(token);
console.log(decoded);

2️⃣ Social Authentication (OAuth Service)

import { oauthService } from 'auth-it';

// Get OAuth Authorization URL
const authUrl = oauthService.getAuthURL('google', {
  clientId: 'your-client-id',
  redirectUri: 'http://localhost:3000/callback',
  scope: 'openid email profile',
});
console.log(authUrl);

// Get Access Token
const token = await oauthService.getToken('google', 'authorization-code', {
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  redirectUri: 'http://localhost:3000/callback',
});
console.log(token);

// Get User Info
const userInfo = await oauthService.getUserInfo('google', token);
console.log(userInfo);

3️⃣ OTP Authentication (OTP Service)

import { otpService } from 'auth-it';

// Send OTP via Email
const otp = await otpService.SendEmailtoOtp('user@example.com');
console.log(otp);

// Verify OTP
const isVerified = otpService.verifyOtp('user@example.com', '123456');
console.log(isVerified); // true or false

📜 License

This package is licensed under the ISC License.


🚀 Now you're ready to integrate auth-it into your application!


Created by Kathan Adalaja 🚀

1.6.4

5 months ago

1.6.3

5 months ago

1.6.2

5 months ago

1.6.5

5 months ago

1.5.5

5 months ago

1.4.6

5 months ago

1.3.7

5 months ago

1.2.8

6 months ago

1.5.4

5 months ago

1.4.5

5 months ago

1.3.6

5 months ago

1.2.7

6 months ago

1.5.3

5 months ago

1.4.4

5 months ago

1.3.5

5 months ago

1.6.1

5 months ago

1.5.2

5 months ago

1.3.4

5 months ago

1.6.0

5 months ago

1.5.1

5 months ago

1.4.2

5 months ago

1.3.3

5 months ago

1.5.0

5 months ago

1.4.1

5 months ago

1.3.2

5 months ago

1.4.0

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.5.9

5 months ago

1.5.8

5 months ago

1.4.9

5 months ago

1.5.7

5 months ago

1.4.8

5 months ago

1.3.9

5 months ago

1.5.6

5 months ago

1.4.7

5 months ago

1.3.8

5 months ago

1.2.9

6 months ago

1.1.6

6 months ago

1.1.7

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago