Documentation ¶
Overview ¶
Package rkmidjwt is a middleware for JWT
Index ¶
- Constants
- type BeforeCtx
- type BootConfig
- type JwtExtractor
- type Option
- func ToOptions(config *BootConfig, entryName, entryType string) []Option
- func WithAuthScheme(scheme string) Option
- func WithClaims(claims jwt.Claims) Option
- func WithEntryNameAndType(entryName, entryType string) Option
- func WithExtractor(ex JwtExtractor) Option
- func WithIgnorePrefix(paths ...string) Option
- func WithKeyFunc(f jwt.Keyfunc) Option
- func WithMockOptionSet(mock OptionSetInterface) Option
- func WithParseTokenFunc(f ParseTokenFunc) Option
- func WithSigningAlgorithm(algo string) Option
- func WithSigningKey(key interface{}) Option
- func WithSigningKeys(key string, value interface{}) Option
- func WithTokenLookup(lookup string) Option
- type OptionSetInterface
- type ParseTokenFunc
Constants ¶
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 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 ¶
WithAuthScheme provide auth scheme. Default is Bearer
func WithEntryNameAndType ¶
WithEntryNameAndType provide entry name and entry type.
func WithExtractor ¶
func WithExtractor(ex JwtExtractor) Option
WithExtractor provide user extractor
func WithIgnorePrefix ¶
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 ¶
WithSigningAlgorithm provide signing algorithm. Default is HS256.
func WithSigningKey ¶
func WithSigningKey(key interface{}) Option
WithSigningKey provide SigningKey.
func WithSigningKeys ¶
WithSigningKeys provide SigningKey with key and value.
func WithTokenLookup ¶
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