Documentation ¶
Overview ¶
Package rkmidjwt is a middleware for JWT
Index ¶
- type AsymmetricConfig
- type BeforeCtx
- type BootConfig
- type JwtExtractor
- type Option
- func ToOptions(config *BootConfig, entryName, entryType string) []Option
- func WithAuthScheme(scheme string) Option
- func WithEntryNameAndType(entryName, entryType string) Option
- func WithExtractor(ex JwtExtractor) Option
- func WithMockOptionSet(mock OptionSetInterface) Option
- func WithPathToIgnore(paths ...string) Option
- func WithSigner(signer rkentry.SignerJwt) Option
- func WithSkipVerify(skipVerify bool) Option
- func WithTokenLookup(lookup string) Option
- type OptionSetInterface
- type ParseTokenFunc
- type SymmetricConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsymmetricConfig ¶ added in v2.0.5
type AsymmetricConfig struct { Algorithm string `yaml:"algorithm" json:"algorithm"` PrivateKey string `yaml:"privateKey" json:"privateKey"` PrivateKeyPath string `yaml:"privateKeyPath" json:"privateKeyPath"` PublicKey string `yaml:"publicKey" json:"publicKey"` PublicKeyPath string `yaml:"publicKeyPath" json:"publicKeyPath"` }
type BeforeCtx ¶
type BeforeCtx struct { Input struct { UrlPath string Request *http.Request UserCtx context.Context } Output struct { JwtToken *jwt.Token ErrResp rkerror.ErrorInterface } }
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"` Ignore []string `yaml:"ignore" json:"ignore"` SignerEntry string `yaml:"signerEntry" json:"signerEntry"` Symmetric *SymmetricConfig `yaml:"symmetric" json:"symmetric"` Asymmetric *AsymmetricConfig `yaml:"asymmetric" json:"asymmetric"` TokenLookup string `yaml:"tokenLookup" json:"tokenLookup"` AuthScheme string `yaml:"authScheme" json:"authScheme"` SkipVerify bool `yaml:"skipVerify" json:"skipVerify"` }
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 WithMockOptionSet ¶
func WithMockOptionSet(mock OptionSetInterface) Option
WithMockOptionSet provide mock OptionSetInterface
func WithPathToIgnore ¶
WithPathToIgnore provide paths prefix that will ignore.
func WithSigner ¶ added in v2.0.5
func WithSigner(signer rkentry.SignerJwt) Option
WithSigner provide rkentry.SignerJwt.
func WithSkipVerify ¶ added in v2.2.0
WithSkipVerify provide skipVerify Default is false
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>" - "cookie:<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 ShouldIgnore(string) bool }
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