auth-it v1.6.5
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
Feature | Description |
---|---|
🔐 JWT Authentication | Securely sign and verify JSON Web Tokens. |
🔑 OAuth Authentication | Integrate authentication with Google, GitHub, Microsoft, and Okta. |
🔏 Password Hashing | Safely hash and validate user passwords using SHA-512. |
🔢 OTP Authentication | Generate 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 🚀
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
5 months ago
5 months ago
5 months ago
6 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago