This project provides a simple implementation of two-factor authentication (2FA) using Node.js, Express, and the speakeasy library.
Make sure you have the following installed on your machine:
- Node.js (https://nodejs.org/)
- npm (Node Package Manager)
- Clone the repository: git clone https://github.com/your-username/two-factor-authentication-example.git
Navigate to the project directory:
cd two-factor-authentication-example
Install dependencies:
npm install
-
Start the server:
npm start
-
Access the API at http://localhost:5000/api.
-
Welcome
Endpoint:
GET /api
Description: Welcome message for the two-factor authentication example. -
Register User
Endpoint:
POST /api/register
Description: Register a user and generate a temporary secret for 2FA. -
Verify Token
Endpoint:
POST /api/verify
Description: Verify the generated token for a registered user. -
Validate Token
Endpoint:
POST /api/validate
Description: Validate a token for a user with an established 2FA secret.
curl -X POST http://localhost:5000/api/register
curl -X POST -H "Content-Type: application/json" -d '{"userId": "user-id", "token": "123456"}' http://localhost:5000/api/verify
curl -X POST -H "Content-Type: application/json" -d '{"userId": "user-id", "token": "123456"}' http://localhost:5000/api/validate
Contributions are welcome! Feel free to open issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.