JWT Aunthentication and Authorization using golang
- Go (Golang) - Backend language
- Fiber - Web framework for Go
- MongoDB - NoSQL database for storing user data
- JWT (JSON Web Tokens) - Token-based authentication
- Docker - Containerization for running MongoDB and API
Essentials:
- Make sure you have docker installed on your system
- Clone the repository and open the project
Run the below command
docker-compose up --build
- Sign Up: Registers a new user with an email and password.
curl -X POST http://localhost:3000/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "securepassword"
}'
- Sign In: Authenticates a user and returns a JWT token.
curl -X POST http://localhost:3000/auth/signin \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "securepassword"
}'
- Refresh Token: Generates a new token using the old one.
curl -X GET http://localhost:3000/auth/refresh \
-H "Authorization: Bearer ${Token}"
- Revoke Token: Invalidates the provided JWT token.
curl -X POST http://localhost:3000/auth/revoke \
-H "Authorization: Bearer ${Token}"
- Get User Details: Fetches the details of the authenticated user.
curl -X GET http://localhost:3000/user/details \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${Token}"
Note:
In the above-mentioned curl requests replace your obtained token with ${Token}