gin_jwt

package
v0.0.0-...-d23ef4a Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CONTEXT_KEY = "_JWT_TOKEN_"

Variables

View Source
var (
	// ErrMissingRealm indicates Realm name is required
	ErrMissingRealm = errors.New("realm is missing")

	ErrMissingSigningAlgorithm = errors.New("signing algorithm is missing")

	ErrMissingKeyFunction = errors.New("key function is missing")

	ErrContextNotHaveToken = errors.New("context not have token")

	// ErrForbidden when HTTP status 403 is given
	ErrForbidden = errors.New("you don't have permission to access this resource")

	// ErrForbidden when HTTP status 403 is given
	ErrNotSupportSigningAlgorithm = errors.New("this signing algorithm NOT support")

	// ErrExpiredToken indicates JWT token has expired. Can't refresh.
	ErrTokenInvalid = errors.New("token is invalid")

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

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

	// ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty
	ErrEmptyQueryToken = errors.New("query token is empty")

	// ErrEmptyCookieToken can be thrown if authing with a cookie, the token cokie is empty
	ErrEmptyCookieToken = errors.New("cookie token is empty")

	// ErrInvalidSigningAlgorithm indicates signing algorithm is invalid, needs to be HS256, HS384, HS512, RS256, RS384 or RS512
	ErrInvalidSigningAlgorithm = errors.New("invalid signing algorithm")

	// ErrInvalidKey indicates the the given public key is invalid
	ErrInvalidKey = errors.New("key invalid")
)

Functions

This section is empty.

Types

type GeneratorConfig

type GeneratorConfig struct {
	Issuer string

	SigningAlgorithm string

	KeyFunc func() interface{}

	NowFunc func() time.Time
}

type JwtGenerator

type JwtGenerator struct {
	// contains filtered or unexported fields
}

func NewGinJwtGenerator

func NewGinJwtGenerator(config GeneratorConfig) (*JwtGenerator, error)

func (*JwtGenerator) GenerateJwt

func (g *JwtGenerator) GenerateJwt(timeout time.Duration,
	refresh time.Duration, claims map[string]interface{}) (string, error)

type JwtMiddleware

type JwtMiddleware struct {
	// contains filtered or unexported fields
}

func NewGinJwtMiddleware

func NewGinJwtMiddleware(config MiddlewareConfig) (*JwtMiddleware, error)

func (*JwtMiddleware) ExtractToken

func (m *JwtMiddleware) ExtractToken(ctx *gin.Context) (*jwt.Token, error)

func (*JwtMiddleware) Handler

func (m *JwtMiddleware) Handler(ctx *gin.Context)

type MiddlewareConfig

type MiddlewareConfig struct {
	Realm string

	SigningAlgorithm string

	KeyFunc func() interface{}

	ErrorHandler func(ctx *gin.Context, err error)

	TokenLookup string

	ContextKey string
}

Jump to

Keyboard shortcuts

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