authenticate

package module
v0.0.0-...-4f050cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2020 License: MIT Imports: 5 Imported by: 0

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TokenAuthMiddleware

func TokenAuthMiddleware(c *gin.Context)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL