Skip to content
/ basic-auth-gin Public template

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 βš™οΈ.

License

Notifications You must be signed in to change notification settings

peterxcli/basic-auth-gin

Repository files navigation

alt tag

License

GitHub release (latest by date)

Go Version

DB Version

Welcome to basic-auth-gin v1

The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to MongoDB database and JWT authentication middleware

Configured with

  • jwt-go: 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
$ ./<your_package_name>

Testing Your Application

$ make test

Acknowledge

thanks Massad -> gin-boilerplate for enabling me to build the gin/mongoDB user auth template

About

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 βš™οΈ.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published