https://github.com/peterxcli/basic-auth-gin
Basic-auth-gin v1 🚀 is a swift RESTful API framework built atop the Gin Framework 🌐 and MongoDB 🗄️. It boasts JWT authentication middleware 🔐, Google OAuth API, SendGrid email API 📧, and SSL support 🔒. Designed for ease of use with environment variable support 🌍, it can be quickly installed and tested using make commands ⚙️.
https://github.com/peterxcli/basic-auth-gin
gin gin-gonic go golang jwt learn mongodb oauth oauth2 restful-api ssl
Last synced: 8 months ago
JSON representation
Basic-auth-gin v1 🚀 is a swift RESTful API framework built atop the Gin Framework 🌐 and MongoDB 🗄️. It boasts JWT authentication middleware 🔐, Google OAuth API, SendGrid email API 📧, and SSL support 🔒. Designed for ease of use with environment variable support 🌍, it can be quickly installed and tested using make commands ⚙️.
- Host: GitHub
- URL: https://github.com/peterxcli/basic-auth-gin
- Owner: peterxcli
- License: mit
- Created: 2023-03-05T07:28:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T20:32:11.000Z (over 2 years ago)
- Last Synced: 2025-08-25T14:02:18.175Z (8 months ago)
- Topics: gin, gin-gonic, go, golang, jwt, learn, mongodb, oauth, oauth2, restful-api, ssl
- Language: Go
- Homepage:
- Size: 112 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://github.com/peterxcli/basic-auth-gin/blob/master/LICENSE)
[](https://github.com/peterxcli/basic-auth-gin/releases)
[](https://github.com/peterxcli/basic-auth-gin/blob/master/go.mod)
[](https://github.com/peterxcli/basic-auth-gin/blob/master/go.mod)
Welcome to **basic-auth-gin** v1
The fastest way to deploy a restful api's with [Gin Framework](https://github.com/gin-gonic/gin/) with a structured project that defaults to **MongoDB** database and **JWT** authentication middleware
## Configured with
- [jwt-go](https://github.com/golang-jwt/jwt): JSON Web Tokens (JWT) as middleware
- Go Modules
- Built-in **Custom Validators**
- Built-in **CORS Middleware**
- Built-in **RequestID Middleware**
- google oauth api
- sendGrid email api
- SSL Support
- Enviroment support
- Unit test
- swagger docs
- And few other important utilties to kickstart any project
-------------------
## Prerequisite
### google oauth api
1. create oauth-client at https://console.cloud.google.com/apis/credentials
2. set `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` in `.env` to your oauth-client id and secret
3. set `REDIRECT_URI` for the google oauth callback
### sendGrid email api
1. if you have your own mail system, you can change the `sendEmail` function at `controllers/user.go:146` and connect to your smtp server
2. if you dont have, try my free alternative: `cloudflare` + `sendgrid`
3. after you get the sengrid email api key, set `SENDGRID_API_KEY` in `.env` to that
### other setting
##### environment variable
* `FRONTEND_URI`: frontend url, this would be use when the google auth callback to bring acess_token to the client
* `EMAIL`: from email
* `REDIRECT_URI`: the redirect uri for google oauth, the endpoint will get the grant code from google oauth
## Installation
```
$ git clone https://github.com/peterxcli/basic-auth-gin.git
```
## Running Your Application
Rename `.env_rename_me` to `.env` and place your credentials
```
$ mv .env_rename_me .env
```
Generate SSL certificates (Optional)
> if you need ssl, change `SSL=FALSE` to `SSL=TRUE` in the `.env` file, then
```
$ make https
```
> Make sure to change the values in .env for your database
```
$ make install
$ make run
```
* every time you run `$ make run` it would regenerate the swagger docs base on your comments
> link to http://localhost:9000/swagger/index.html to view the openAPI docs
## Building Your Application
```
$ go build -v
```
```
$ ./
```
## Testing Your Application
```
$ make test
```
---
## Acknowledge
thanks [Massad -> gin-boilerplate](https://github.com/Massad/gin-boilerplate)
for enabling me to build the gin/mongoDB user auth template