Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

zblocks/middleware-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Middleware library to handle jwt

Work with library

  1. import the package using the commands in your project
import (
	"github.com/zblocks/middleware-lib"
)

Inside terminal run

go get github.com/zblocks/middleware-lib
  1. Functions included in the library
func VerifyJwtToken(c *gin.Context, jwtSecret string) (bool, jwt.MapClaims, int, error)
func SetCors(r *gin.Engine) 
  1. Variables defined in the library
var ErrAuthorizationTokenEmpty = 20003
var ErrAuthorizationTokenInvalid = 20004

var AuthorizationTokenEmpty = "authorization token not provided"
var AuthorizationTokenInvalid = "authorization token invalid"

Mock middleware in test

Example mocking middleware functions VerifyJwtTokenV2() in your service

  1. In your test function replace MiddlewareHandler interface with the mock interface
middleware.MiddlewareHandler = middlewareMock.MiddlewareMock
  1. Define mocking behavior for the function
	middlewareMock.MiddlewareMock.On("VerifyJwtTokenV2", mock.AnythingOfType("*gin.Context"), "<auth_service_base_url>").Return(true)