rkmidjwt

package
v2.2.22 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 16

Documentation

Overview

Package rkmidjwt is a middleware for JWT

Index

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 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 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 WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithPathToIgnore

func WithPathToIgnore(paths ...string) Option

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

func WithSkipVerify(skipVerify bool) Option

WithSkipVerify provide skipVerify Default is false

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>" - "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

type SymmetricConfig added in v2.0.5

type SymmetricConfig struct {
	Algorithm string `yaml:"algorithm" json:"algorithm"`
	Token     string `yaml:"token" json:"token"`
	TokenPath string `yaml:"tokenPath" json:"tokenPath"`
}

Jump to

Keyboard shortcuts

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