barryblando / auth-api

Auth REST API with 🤖Node.js, 📜TypeScript, 🎛️Typegoose &🚔Zod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authentication & Authorization REST API

Features

  1. Register a user
  2. Verify user's email address
  3. Send forgot password via email
  4. Reset password
  5. Get current user
  6. Login
  7. Logout
  8. Access token
  9. Refresh tokens
  10. API Restriction (Authorization)
  11. TDD
  12. Swagger Docs (OpenAPI)
  13. Performance Metrics

Tech Stack Used

Tech Stack Used (For Testing)

  • jest - Testing framework
  • ts-jest - A Jest transformer with source map support that lets you use Jest to test projects written in TS.
  • MongoDB In-Memory Server - DB for mocking/testing that is isolated
  • Supertest - provide a high-level abstraction for testing HTTP

Tech Stack Used (For Documenting APIs)

  • swagger-js-doc - reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) spec
  • swagger-ui-express - auto-generate swagger-ui generated API docs from express

Tech Stack Used (For Performance Metrics)

Tools Used

Structure

  1. User API
    1. Create user
    2. Verify user
    3. Request reset password code
    4. Reset password
    5. Get current user
  2. Authentication API
    1. Create user session
    2. Delete user session
    3. Get new access token with refresh tokens

Generating Keys

  • Generate new keys: JSEncrypt
    • RSA 1024 bit
  • Base64 encode the keys: Base64Encode
    • Private and Public Keys for Access and Refresh

Access & Refresh Token Flow

graph TD
    A[Authorized Request]--> B{Is the access token valid?}
    B -->|NO| C(Return Unauthorized error)
    B -->|YES| D{Has the access token expired?}
    D -->|YES| E{Is a valid refresh token included?}
    D -->|NO| F["Process request (Go to route handler)"]
    E -->|YES| G(Issue a new access token)
    E -->|NO| C

About

Auth REST API with 🤖Node.js, 📜TypeScript, 🎛️Typegoose &🚔Zod

License:GNU General Public License v3.0


Languages

Language:TypeScript 100.0%