jwt

package module
v0.0.0-...-a5ce2d4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 7 Imported by: 0

README

GO JWT Validate

Table of Contents

About The Project

This is a simple gin middleware to validate JWT tokens with a given public key.

It is mostly inspired by gin-jwt.

Built With

Getting Started

Briefly describe how a new developer can run the project and get started.

Installation
go get  ...

Usage

See example.go

Roadmap

Describe or link to any planned work for this project.:w

Contributing

Contributions are welcomed and appreciated 😊.

License

MIT. Seee LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Auth header needs to be set
	ErrEmptyAuthHeader = errors.New("middleware header is empty")

	// ErrInvalidAuthHeader indicates middleware header is invalid, could for example have the wrong Realm name
	ErrInvalidAuthHeader = errors.New("middleware header is invalid")

	ErrInvalidKeyPath = errors.New("middleware pub key path is invalid")
)

Functions

func GetToken

func GetToken(c *gin.Context) string

GetToken help to get the JWT token string

Types

type JWTMiddleware

type JWTMiddleware struct {
	PubKeyPath string

	HeaderName   string
	HeaderPrefix string
	// contains filtered or unexported fields
}

func NewJWTValidationMiddleware

func NewJWTValidationMiddleware(jwtm *JWTMiddleware) (*JWTMiddleware, error)

func (*JWTMiddleware) GetClaimsFromJWT

func (jwtm *JWTMiddleware) GetClaimsFromJWT(c *gin.Context) (MapClaims, error)

GetClaimsFromJWT get claims from JWT token

func (*JWTMiddleware) TokenValidationMiddleware

func (jwtm *JWTMiddleware) TokenValidationMiddleware() gin.HandlerFunc

func (*JWTMiddleware) VerifyToken

func (jwtm *JWTMiddleware) VerifyToken(c *gin.Context) (*jwt.Token, error)

VerifyToken verifies the token is valid and signed with the correct key

type MapClaims

type MapClaims = map[string]interface{}

func ExtractClaims

func ExtractClaims(c *gin.Context) MapClaims

ExtractClaims help to extract the JWT claims

func ExtractClaimsFromToken

func ExtractClaimsFromToken(token *jwt.Token) MapClaims

ExtractClaimsFromToken help to extract the JWT claims from token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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