{"_id":"5way_auth_package","name":"5way_auth_package","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"5way_auth_package","version":"1.0.0","description":"package for 5 way auth","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"author":{"name":"dipak jha"},"license":"ISC","devDependencies":{"@types/express":"^5.0.0","@types/jsonwebtoken":"^9.0.8","@types/node":"^22.13.0","@types/nodemailer":"^6.4.17","@types/speakeasy":"^2.0.10","typescript":"^5.7.3"},"dependencies":{"axios":"^1.7.9","crypto":"^1.0.1","jsonwebtoken":"^9.0.2","nodemailer":"^6.10.0","speakeasy":"^2.0.0"},"_id":"5way_auth_package@1.0.0","_nodeVersion":"20.14.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Sqqx08PC7s0hi/0vI2Vgxa9p4rBB0H7rP/VIiqDQ8XTHB2CLR2+bl4bsyk85Nu9S0Vt9TsjpTZlbq4LrpsRw6w==","shasum":"089acbbd1e045503cebe6a32328376e9088f4dfc","tarball":"https://registry.npmjs.org/5way_auth_package/-/5way_auth_package-1.0.0.tgz","fileCount":27,"unpackedSize":43745,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAKmNc28EBIRAS1ejRIqPC+XAwUDcw5UkhvR3X7QYjc3AiEA4S5d3jEDiUpChO3xYxZALoCeh4BuFzW3bpF5xG/TTxk="}]},"_npmUser":{"name":"dipak_jha","email":"dipakjha4200@gmail.com"},"directories":{},"maintainers":[{"name":"dipak_jha","email":"dipakjha4200@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/5way_auth_package_1.0.0_1738562927147_0.35869505747608255"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-03T06:08:47.146Z","1.0.0":"2025-02-03T06:08:47.331Z","modified":"2025-02-03T06:08:47.586Z"},"maintainers":[{"name":"dipak_jha","email":"dipakjha4200@gmail.com"}],"description":"package for 5 way auth","author":{"name":"dipak jha"},"license":"ISC","readme":"# 5-Way Authentication Package for Node.js Applications\n\nThis package provides a comprehensive authentication solution for Node.js applications, offering five different authentication methods: OTP, JWT, Password-based, Two-Factor Authentication (2FA), and Social SSO.\n\n## Project Description\n\nThe 5-Way Authentication Package is designed to simplify and streamline the implementation of various authentication methods in Node.js applications. It offers a flexible and modular approach to authentication, allowing developers to easily integrate one or more authentication methods into their projects.\n\nKey features of this package include:\n\n- One-Time Password (OTP) generation, email delivery, and verification\n- JSON Web Token (JWT) creation and verification\n- Password-based authentication with secure hashing\n- Two-Factor Authentication (2FA) using Time-based One-Time Passwords (TOTP)\n- Social Single Sign-On (SSO) integration with support for multiple providers\n\nThis package is ideal for developers looking to implement robust authentication systems in their Node.js applications without having to build each authentication method from scratch.\n\n## Repository Structure\n\n```\n.\n├── dist/                 # Compiled JavaScript files\n├── src/                  # TypeScript source files\n│   ├── auth/\n│   │   ├── 2fa/          # Two-Factor Authentication\n│   │   ├── otp/          # One-Time Password\n│   │   ├── password_based/\n│   │   │   ├── jwt_logic/\n│   │   │   ├── password/\n│   │   │   └── types/\n│   │   └── social_sso/   # Social Single Sign-On\n│   ├── index.ts          # Main entry point\n│   └── Readme.md\n├── package.json          # Project dependencies and scripts\n└── tsconfig.json         # TypeScript configuration\n```\n\nKey Files:\n- `src/index.ts`: Main entry point that exports all authentication functionalities\n- `package.json`: Defines project dependencies and build scripts\n- `tsconfig.json`: Configures TypeScript compiler options\n\n## Usage Instructions\n\n### Installation\n\n1. Ensure you have Node.js (version 12 or higher) installed.\n2. Install the package in your project:\n\n```bash\nnpm install 5way_auth_package\n```\n\n### Getting Started\n\n1. Import the desired authentication methods in your application:\n\n```typescript\nimport { generateOtp, sendOtpToEmail, verifyOtp, createToken, verifyToken, HashVerifier, generateSecret, verifyTOTP, handleOAuthCallback } from '5way_auth_package';\n```\n\n2. Configure the authentication methods you want to use. Here's an example of setting up OTP authentication:\n\n```typescript\nimport { generateOtp, sendOtpToEmail, verifyOtp } from '5way_auth_package';\n\n// Generate and send OTP\nconst email = 'user@example.com';\nconst senderEmailConfig = {\n  user: 'your-email@gmail.com',\n  pass: 'your-email-password'\n};\nconst emailTemplate = ''; // Your custom email template\n\nconst otp = await sendOtpToEmail(email, senderEmailConfig, emailTemplate);\n\n// Verify OTP\nconst isValid = verifyOtp(email, otp);\n```\n\n### Configuration Options\n\nEach authentication method has its own configuration options. Here are some examples:\n\n1. JWT Configuration:\n\n```typescript\nconst secret = 'your-secret-key';\nconst payload = { userId: '123' };\nconst token = createToken(payload, secret, { expiresIn: '1h' });\n```\n\n2. Password-based Authentication Configuration:\n\n```typescript\nconst hashConfig = {\n  algorithm: 'sha256',\n  includedFields: ['username', 'password'],\n  storedField: 'hashedPassword'\n};\nconst hashVerifier = new HashVerifier(hashConfig);\n```\n\n3. 2FA Configuration:\n\n```typescript\nconst secret = generateSecret();\nconst isValid = verifyTOTP(secret, userProvidedToken);\n```\n\n### Common Use Cases\n\n1. Implementing OTP-based login:\n\n```typescript\n// Generate and send OTP\nconst otp = await sendOtpToEmail(userEmail, emailConfig, emailTemplate);\n\n// Verify OTP\nif (verifyOtp(userEmail, userProvidedOtp)) {\n  // Grant access\n} else {\n  // Deny access\n}\n```\n\n2. JWT-based authentication:\n\n```typescript\n// Create token on login\nconst token = createToken({ userId: user.id }, secretKey);\n\n// Verify token on protected routes\nconst payload = verifyToken(token, secretKey);\nif (payload) {\n  // Allow access to protected resource\n} else {\n  // Deny access\n}\n```\n\n3. Social SSO integration:\n\n```typescript\nconst oauthConfig = {\n  clientId: 'your-client-id',\n  clientSecret: 'your-client-secret',\n  redirectUri: 'your-redirect-uri',\n  tokenUrl: 'https://provider.com/oauth/token',\n  userInfoUrl: 'https://provider.com/oauth/userinfo'\n};\n\nconst userInfo = await handleOAuthCallback(authorizationCode, oauthConfig);\n```\n\n### Testing & Quality\n\nTo run tests:\n\n```bash\nnpm test\n```\n\n### Troubleshooting\n\nCommon issues and solutions:\n\n1. OTP not received:\n   - Check spam folder\n   - Verify email configuration\n   - Ensure proper network connectivity\n\n2. JWT verification fails:\n   - Check if the token has expired\n   - Verify that the correct secret key is being used\n\n3. 2FA verification fails:\n   - Ensure the user's device time is synchronized\n   - Verify that the correct secret is being used\n\nFor debugging, enable verbose logging by setting the `DEBUG` environment variable:\n\n```bash\nDEBUG=5way_auth_package:* node your-app.js\n```\n\nLog files can be found in the `logs` directory of your application.\n\n## Data Flow\n\nThe authentication process in this package follows a general flow:\n\n1. User initiates authentication (e.g., enters email for OTP, provides credentials for password-based auth)\n2. Application generates necessary authentication data (OTP, JWT, etc.)\n3. Data is sent to the user (e.g., OTP via email) or stored securely (e.g., hashed password)\n4. User provides authentication data (OTP, password, token)\n5. Application verifies the provided data\n6. Access is granted or denied based on verification result\n\n```\n[User] -> [Application] -> [Authentication Module] -> [Storage/Email]\n   ^                                                         |\n   |                                                         v\n[Verification] <- [Application] <- [User Input] <- [User receives data]\n```\n\n## Deployment\n\nThis package is designed to be integrated into your Node.js application. Deploy your application as you normally would, ensuring that all environment variables and configurations are properly set for the authentication methods you're using.","readmeFilename":"README.md"}