Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/watchakorn-18k/go-otp-fiber
This repository features a straightforward implementation of OTP (One-Time Password) authentication using Go, the Fiber framework, and MongoDB. OTP adds an extra layer of security to user logins beyond traditional passwords.
https://github.com/watchakorn-18k/go-otp-fiber
2factor fiber-framework go golang google-authenticator microsoft-authenticator
Last synced: 2 days ago
JSON representation
This repository features a straightforward implementation of OTP (One-Time Password) authentication using Go, the Fiber framework, and MongoDB. OTP adds an extra layer of security to user logins beyond traditional passwords.
- Host: GitHub
- URL: https://github.com/watchakorn-18k/go-otp-fiber
- Owner: watchakorn-18k
- Created: 2024-07-03T14:24:04.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-07-09T16:32:13.000Z (4 months ago)
- Last Synced: 2024-07-09T21:05:38.726Z (4 months ago)
- Topics: 2factor, fiber-framework, go, golang, google-authenticator, microsoft-authenticator
- Language: Go
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Go OTP Fiber Application
[api-version](https://github.com/watchakorn-18k/go-otp-fiber/tree/master)/[htmx-version](https://github.com/watchakorn-18k/go-otp-fiber/tree/show-html-version)
This project is a simple OTP (One Time Password) generation and verification service built using the Go programming language and the Fiber web framework. It uses TOTP (Time-based One-Time Password) for generating and verifying OTPs.
## Features
- Generate a TOTP key for a user and return the QR code image.
- Verify the TOTP code provided by the user.## Prerequisites
- Go 1.22+
- MongoDB
- Fiber framework## Getting Started
### Installation
1. Clone the repository:
```sh
git clone https://github.com/watchakorn-18k/go-otp-fiber
cd go-otp-fiber
```2. Install dependencies:
```sh
go mod tidy
```3. Set up your MongoDB database and update the connection string in the `domain` package.
### Running the Application
1. Start the application:
```sh
go run main.go
```2. The server will start on port `3000`.
### API Endpoints
#### Generate TOTP Key
- **Endpoint:** `GET /api/otp/generate_link/:username`
- **Description:** Generates a TOTP key for the specified username and returns the secret, URL, and QR code image.
- **Parameters:**
- `username`: The username for which to generate the TOTP key.- **Response:**
```json
{
"secret": "generated-secret",
"url": "otpauth-url",
"qrcode": "base64-encoded-qrcode"
}
```#### Verify TOTP Code
- **Endpoint:** `POST /api/otp/verify_otp`
- **Description:** Verifies the TOTP code provided by the user.
- **Request Body:**```json
{
"username": "user123",
"otp": "123456"
}
```- **Response:**
- Success:
```json
{
"message": "valid OTP"
}
```- Failure:
```json
{
"message": "invalid OTP"
}
```### Dependencies
- [Fiber](https://github.com/gofiber/fiber): An Express-inspired web framework for Go.
- [MongoDB Go Driver](https://github.com/mongodb/mongo-go-driver): The official MongoDB driver for Go.
- [pquerna/otp](https://github.com/pquerna/otp): A Go library for generating and verifying TOTP/HOTP codes.## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.