Golang & MongoDB: JWT Authentication and Authorization
In this article, you'll learn how to implement RS256 JWT (JSON Web Token) Authentication and Authorization with Golang, Gin Gonic, MongoDB-Go-driver, and Docker-compose.
Topics Covered
- Golang & MongoDB JWT Authentication Overview
- JWT Authentication Example with Golang and MongoDB
- How to Generate Public and Private Keys
- Update Environment Variables with Viper
- Creating the User models with structs
- Creating an Auth and User Interfaces
- Authentication Interface
- User Interface
- Create utility functions to hash and verify password
- Create services that interact with the database
- Auth interface implementation
- User interface implementation
- Create a utility function to sign and verify JWT tokens
- Create Json Web Token
- Verify JSON Web Token
- Create the authentication controllers
- Signup user controller
- Login user controller
- Refresh access token controller
- Logout user controller
- Authentication Middleware Guard
- Create the user controllers
- Create API Routes with Gin
- Add the Routes to the Gin Middleware Pipeline
Read the entire article here: https://codevoweb.com/golang-mongodb-jwt-authentication-authorization
Articles in this series:
1. API with Golang + MongoDB + Redis + Gin Gonic: Project Setup
API with Golang + MongoDB + Redis + Gin Gonic: Project Setup
2. Golang & MongoDB: JWT Authentication and Authorization
Golang & MongoDB: JWT Authentication and Authorization
3. API with Golang + MongoDB: Send HTML Emails with Gomail
API with Golang + MongoDB: Send HTML Emails with Gomail
4. API with Golang, Gin Gonic & MongoDB: Forget/Reset Password
API with Golang, Gin Gonic & MongoDB: Forget/Reset Password
5. Build Golang gRPC Server and Client: SignUp User & Verify Email
Build Golang gRPC Server and Client: SignUp User & Verify Email
6. Build Golang gRPC Server and Client: Access & Refresh Tokens
Build Golang gRPC Server and Client: Access & Refresh Tokens
7. Build CRUD RESTful API Server with Golang, Gin, and MongoDB
Build CRUD RESTful API Server with Golang, Gin, and MongoDB
8. Build CRUD gRPC Server API & Client with Golang and MongoDB
Build CRUD gRPC Server API & Client with Golang and MongoDB
golang-mongodb
golang-mongodb