@rline/auth
TypeScript icon, indicating that this package has built-in type declarations

7.0.0 • Public • Published

Authorization and Authentication Service

Overview

The Authorization and Authentication Service is a robust and scalable system designed to manage user authentication and session management for multiple devices. It provides a secure interface for user login, single sign-on (SSO), logout, and password management operations. This service supports multiple concurrent sessions across different devices, ensuring seamless user experiences.

Features

  • Login: Authenticate users with their username and password.
  • Login with SSO: Provide Single Sign-On functionality using external identity providers.
  • Logout: Log out from the current session.
  • Logout All: Log out from all active sessions across devices.
  • Forgot Password: Initiate a password reset process by sending a reset link to the registered email address.
  • Reset Password: Allow users to reset their password using a secure token.
  • Multiple Sessions: Support multiple simultaneous sessions for the same user on different devices.

Installation

Prerequisites

  • NestJS
  • Typeorm

API Endpoints

1. Login

POST /auth/login

Request Body:

{
  "username": "user@example.com",
  "password": "your_password"
}

Response:

{
  "message": "Login successful",
  "token": "jwt_token",
  "sessionId": "session_id"
}

2. Login with SSO

POST /auth/login-sso

Request Body:

{
  "provider": "google",
  "token": "sso_provider_token"
}

Response:

{
  "message": "Login successful",
  "token": "jwt_token",
  "sessionId": "session_id"
}

3. Logout

POST /auth/logout

Request Body:

{
  "sessionId": "session_id"
}

Response:

{
  "message": "Logout successful"
}

4. Logout All

POST /auth/logout-all

Request Body:

{
  "userId": "user_id"
}

Response:

{
  "message": "Logged out from all sessions"
}

5. Forgot Password

POST /auth/forgot-password

Request Body:

{
  "email": "user@example.com"
}

Response:

{
  "message": "Password reset link sent to email"
}

6. Reset Password

POST /auth/reset-password

Request Body:

{
  "token": "reset_token",
  "newPassword": "new_password"
}

Response:

{
  "message": "Password reset successful"
}

Configuration

Environment Variables

Variable Description Example
DATABASE_URL Database connection string postgres://localhost:27017
JWT_SECRET Secret key for signing JWTs your_secret_key
EMAIL_SERVICE Email service provider gmail
EMAIL_USER Email service username your_email@gmail.com
EMAIL_PASSWORD Email service password your_email_password

Package Sidebar

Install

npm i @rline/auth

Weekly Downloads

18

Version

7.0.0

License

none

Unpacked Size

7.77 kB

Total Files

9

Last publish

Collaborators

  • rbrightline