New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

auth-it

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth-it

A comprehensive authentication package providing:

latest
npmnpm
Version
1.6.5
Version published
Maintainers
0
Created
Source

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
  • Installation
  • Environment Variables
  • Usage
  • API Reference
  • License

🚀 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 🚀

Keywords

npm

FAQs

Package last updated on 11 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts