rkmidjwt

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Overview

Package rkmidjwt is a middleware for JWT

Index

Constants

View Source
const (
	// AlgorithmHS256 is default algorithm for jwt
	AlgorithmHS256 = "HS256"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BeforeCtx

type BeforeCtx struct {
	Input struct {
		UrlPath string
		Request *http.Request
		UserCtx context.Context
	}
	Output struct {
		JwtToken *jwt.Token
		ErrResp  *rkerror.ErrorResp
	}
}

BeforeCtx context for Before() function

func NewBeforeCtx

func NewBeforeCtx() *BeforeCtx

NewBeforeCtx create new BeforeCtx with fields initialized

type BootConfig

type BootConfig struct {
	Enabled      bool     `yaml:"enabled" json:"enabled"`
	IgnorePrefix []string `yaml:"ignorePrefix" json:"ignorePrefix"`
	SigningKey   string   `yaml:"signingKey" json:"signingKey"`
	SigningKeys  []string `yaml:"signingKeys" json:"signingKeys"`
	SigningAlgo  string   `yaml:"signingAlgo" json:"signingAlgo"`
	TokenLookup  string   `yaml:"tokenLookup" json:"tokenLookup"`
	AuthScheme   string   `yaml:"authScheme" json:"authScheme"`
}

BootConfig for YAML

type JwtExtractor

type JwtExtractor func(ctx context.Context) (string, error)

type Option

type Option func(*optionSet)

Option if for middleware options while creating middleware

func ToOptions

func ToOptions(config *BootConfig, entryName, entryType string) []Option

ToOptions convert BootConfig into Option list

func WithAuthScheme

func WithAuthScheme(scheme string) Option

WithAuthScheme provide auth scheme. Default is Bearer

func WithClaims

func WithClaims(claims jwt.Claims) Option

WithClaims provide jwt.Claims.

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithExtractor

func WithExtractor(ex JwtExtractor) Option

WithExtractor provide user extractor

func WithIgnorePrefix

func WithIgnorePrefix(paths ...string) Option

WithIgnorePrefix provide paths prefix that will ignore. Mainly used for swagger main page and RK TV entry.

func WithKeyFunc

func WithKeyFunc(f jwt.Keyfunc) Option

WithKeyFunc provide user defined key func.

func WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithParseTokenFunc

func WithParseTokenFunc(f ParseTokenFunc) Option

WithParseTokenFunc provide user defined token parse func.

func WithSigningAlgorithm

func WithSigningAlgorithm(algo string) Option

WithSigningAlgorithm provide signing algorithm. Default is HS256.

func WithSigningKey

func WithSigningKey(key interface{}) Option

WithSigningKey provide SigningKey.

func WithSigningKeys

func WithSigningKeys(key string, value interface{}) Option

WithSigningKeys provide SigningKey with key and value.

func WithTokenLookup

func WithTokenLookup(lookup string) Option

WithTokenLookup provide lookup configs. TokenLookup is a string in the form of "<source>:<name>" or "<source>:<name>,<source>:<name>" that is used to extract token from the request. Optional. Default value "header:Authorization". Possible values: - "header:<name>" - "query:<name>" - "param:<name>" - "cookie:<name>" - "form:<name>" Multiply sources example: - "header: Authorization,cookie: myowncookie"

type OptionSetInterface

type OptionSetInterface interface {
	GetEntryName() string

	GetEntryType() string

	Before(*BeforeCtx)

	BeforeCtx(*http.Request, context.Context) *BeforeCtx
}

OptionSetInterface mainly for testing purpose

func NewOptionSet

func NewOptionSet(opts ...Option) OptionSetInterface

NewOptionSet Create new optionSet with options.

func NewOptionSetMock

func NewOptionSetMock(before *BeforeCtx) OptionSetInterface

NewOptionSetMock for testing purpose

type ParseTokenFunc

type ParseTokenFunc func(auth string) (*jwt.Token, error)

ParseTokenFunc parse token func

Jump to

Keyboard shortcuts

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