https://github.com/varunsathreya/go-jwt-auth
A basic server written in Go for the JWT Authentication and Authorization based on user type.
https://github.com/varunsathreya/go-jwt-auth
docker docker-compose gin-gonic go golang jwt mongodb
Last synced: 4 months ago
JSON representation
A basic server written in Go for the JWT Authentication and Authorization based on user type.
- Host: GitHub
- URL: https://github.com/varunsathreya/go-jwt-auth
- Owner: VarunSAthreya
- License: mit
- Created: 2022-07-17T16:03:48.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T00:18:55.000Z (over 2 years ago)
- Last Synced: 2025-04-01T08:49:48.994Z (about 1 year ago)
- Topics: docker, docker-compose, gin-gonic, go, golang, jwt, mongodb
- Language: Go
- Homepage:
- Size: 81.1 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JWT Authentication using GO
This is a basic server written in Go for the JWT Authentication and Authorization based on user type.
## Tech Stack
- [Go](https://golang.org/)
- [Gin](https://github.com/gin-gonic/gin)
- [JWT](https://jwt.io/)
- [MongoDB](https://www.mongodb.com/)
## Routes
- `/users/signup`:
- Sign Up for a user.
- Requires data in the body:
```json
{
"first_name": "John",
"last_name": "Doe",
"email": "john@doe.com",
"password": "password",
"phone": "1234567890",
"user_type": "ADMIN" // Can only be "ADMIN" or "USER"
}
```
- Returns user ID.
- `/users/signin`:
- Sign In for a user.
- Requires data in the body:
```json
{
"email": "john@doe.com",
"password": "password"
}
```
- Returns User object.
- `/users/:id`:
- Get a user by ID.
- Requires `Authorization` token in request Header.
- Returns User object.
- `/users`:
- Get all users, only available for `ADMIN` user type.
- Requires `Authorization` token and `uid` (User ID) in request Header.
- Returns total count and all users.
## Installation
### Prerequisites
- [Docker](https://www.docker.com/)
### Environment Variables
Create a `.env` file in the root directory of the project.
```.env
PORT = 8000
MONGO_URL = mongodb://mongo:27017/
SECRET_KEY =
```
- In `MONGO_URL` it is "mongodb://`mongo`:27017/\" where `mongo` is the name of the container.
- And change in `PORT` number should also be done in `Dockerfile` and `docker-compose.yml` files.
### Build
```bash
docker-compose build
```
### Run
```bash
docker-compose up
```