https://github.com/codecat1111/2fa-using-speakeasy
This project implements a simple Two-Factor Authentication (2FA) system using Speakeasy and Express.js. The system allows users to register and verify their identity using TOTP (Time-based One-Time Password).
https://github.com/codecat1111/2fa-using-speakeasy
Last synced: 10 months ago
JSON representation
This project implements a simple Two-Factor Authentication (2FA) system using Speakeasy and Express.js. The system allows users to register and verify their identity using TOTP (Time-based One-Time Password).
- Host: GitHub
- URL: https://github.com/codecat1111/2fa-using-speakeasy
- Owner: codecat1111
- Created: 2024-08-07T14:08:48.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T14:15:57.000Z (almost 2 years ago)
- Last Synced: 2025-06-11T09:08:50.534Z (about 1 year ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Two-Factor Authentication (2FA) Project
This project implements a simple Two-Factor Authentication (2FA) system using Speakeasy and Express.js. The system allows users to register and verify their identity using TOTP (Time-based One-Time Password).
## Features
- User registration with a unique ID and TOTP secret generation.
- Verification of TOTP tokens.
- Validation of TOTP tokens.
- Simple in-memory storage using node-json-db.
## Prerequisites
- Node.js
- npm (Node Package Manager)
## Installation
1. Clone the repository:
```bash
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
```
2. Install dependencies:
```bash
npm install
```
## Usage
1. Start the server:
```bash
node app.js
```
2. The server will be running on `http://localhost:9000`.
## API Endpoints
### Register a User
- **URL:** `/api/register`
- **Method:** `POST`
- **Description:** Registers a new user and generates a TOTP secret.
- **Response:**
```json
{
"id": "user-id",
"secret": "base32-encoded-secret"
}
```
### Verify TOTP Token
- URL: /api/verify
- Method: POST
- Description: Verifies a user's TOTP token.
- Request Body:
```json
{
"userId": "user-id",
"token": "totp-token"
}
```
- Response:
```json
{
"verified": true
}
```
### Validate TOTP Token
- URL: /api/validate
- Method: POST
- Description: Validates a user's TOTP token.
- Request Body:
```json
{
"userId": "user-id",
"token": "totp-token"
}
```
- Response:
```json
{
"validated": true
}
```