Categorygithub.com/yankeetube/gin-jwt-middleware
modulepackage
0.0.0-20200602052712-4f050ccf75f5
Repository: https://github.com/yankeetube/gin-jwt-middleware.git
Documentation: pkg.go.dev

# README

gin-jwt-middleware

Reference - ENG
Reference - KOR

What is JWT?

JSON Web Token (JWT) more information: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html

Quick Start

Install package

$ go get github.com/YankeeTube/gin-jwt-middleware

In your gin application main.go, import the package

import (
    "github.com/YankeeTube/gin-jwt-middleware"
)

Use the middleware

// ApiMiddleware will add the db connection to the context
func ApiMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		privateBytes := strings.Replace(os.Getenv("PRIVATE_KEY"), "\\n", "\n", -1)
		block, _ := pem.Decode([]byte(privateBytes))
		privateKey, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
		c.Set("PRIVKEY", privateKey)
		c.Next()
	}
}

api := gin.Default()
api.Use(ApiMiddleware)  // Private Key Settings of Context
api.Use(authenticate.TokenAuthMiddleware)  // Jwt Token Check

# Functions

No description provided by the author