Skip to content

manubravo/mock-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ Mock Auth API

Fake authentication API for development and testing environments. Ideal for quick integrations with frontends or microservices that require login/logout/verify without implementing a real authentication system.

🚀 Features

  • Login and Logout with cookies or Bearer token.
  • Session verification (/auth/verify).
  • User listing without passwords.
  • Audit logs for every login/logout.
  • In-memory sessions (Map).

📦 Installation

git clone https://github.com/manubravo/mock-auth
cd mock-auth
npm install

▶️ Usage

npm start

By default, it listens on http://localhost:4000.

📚 Available Endpoints

GET /auth/users

Returns all available users without passwords.
💡 Useful to see which users are available for testing.


POST /auth/login

Body:

{
  "email": "[email protected]",
  "password": "test"
}

Response:

{
  "token": "uuid-token",
  "user": {
    "id": "1",
    "email": "[email protected]",
    "role": "superadmin"
  }
}

📝 Also sets a sessionToken cookie.


POST /auth/logout

Closes the current session and deletes the token.

  • Supports:
    • Header: Authorization: Bearer <token>
    • Cookie: sessionToken

POST /auth/verify

Checks if a session is valid.

  • Supports:
    • Header: Authorization: Bearer <token>
    • Cookie: sessionToken

Response if valid:

{
  "valid": true,
  "user": {
    "id": "1",
    "email": "[email protected]",
    "role": "superadmin"
  }
}

GET /auth/logs

Returns all login/logout audit logs.
⚠️ For development use only.


👤 Default Users

ID Email Password Role
1 [email protected] test superadmin
2 [email protected] test admin
3 [email protected] test admin
4 [email protected] test editor

🔐 Technical Details

  • Sessions managed with Map() (no persistence).
  • UUID v4 tokens.
  • HTTP Only cookies for better security.
  • Middleware for parsing body and cookies.

🛠️ Stack

  • Node.js + Express
  • UUID for tokens
  • body-parser and cookie-parser

⚠️ Warning

This API must not be used in production. It does not hash passwords or implement protection against common attacks (CSRF, Brute Force, etc). For testing or quick integration in local projects

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published