jwt

package
v1.5.3-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyJwtContext = errors.New("empty jwt context")
	ErrNoPermission    = errors.New("no permission")
)
View Source
var BuiltInTokenValidateFn func(context.Context, string) (interface{}, error, bool)
View Source
var InvalidSigningMethod = errors.New("invalid SigningMethod type")
View Source
var SigningMethods = map[SigningMethod]jwt.SigningMethod{
	SIGNING_METHOD_UNKNOWN:    jwt.SigningMethodNone,
	SIGNING_METHOD__ECDSA256:  jwt.SigningMethodES256,
	SIGNING_METHOD__ECDSA384:  jwt.SigningMethodES384,
	SIGNING_METHOD__ECDSA512:  jwt.SigningMethodES512,
	SIGNING_METHOD__HMAC256:   jwt.SigningMethodHS256,
	SIGNING_METHOD__HMAC384:   jwt.SigningMethodHS384,
	SIGNING_METHOD__HMAC512:   jwt.SigningMethodHS512,
	SIGNING_METHOD__RSA256:    jwt.SigningMethodRS256,
	SIGNING_METHOD__RSA384:    jwt.SigningMethodRS384,
	SIGNING_METHOD__RSA512:    jwt.SigningMethodRS512,
	SIGNING_METHOD__RSAPSS256: jwt.SigningMethodPS256,
	SIGNING_METHOD__RSAPSS384: jwt.SigningMethodPS384,
	SIGNING_METHOD__RSAPSS512: jwt.SigningMethodPS512,
}
View Source
var WithPermissionFn func(interface{}) bool

Functions

func AuthFromContext

func AuthFromContext(ctx context.Context) interface{}

func SetBuiltInTokenFn

func SetBuiltInTokenFn(f func(context.Context, string) (interface{}, error, bool))

func SetWithPermissionFn

func SetWithPermissionFn(f func(interface{}) bool)

func WithConfContext

func WithConfContext(jwt *Jwt) func(context.Context) context.Context

Types

type Auth

type Auth struct {
	AuthInQuery  string `name:"authorization,omitempty" in:"query"  validate:"@string[1,]"`
	AuthInHeader string `name:"Authorization,omitempty" in:"header" validate:"@string[1,]"`
}

func (Auth) ContextKey

func (r Auth) ContextKey() interface{}

func (Auth) Output

func (r Auth) Output(ctx context.Context) (pl interface{}, err error)

type Claims

type Claims struct {
	Payload interface{}
	jwt.RegisteredClaims
}

type Error

type Error int
const (
	Unauthorized Error = http.StatusUnauthorized*1e6 + iota + 1
	// @errTalk Invalid Token
	InvalidToken
	// @errTalk Invalid Claim
	InvalidClaim
)

func (Error) CanBeTalk

func (v Error) CanBeTalk() bool

func (Error) Code

func (v Error) Code() int

func (Error) Error

func (v Error) Error() string

func (Error) Key

func (v Error) Key() string

func (Error) Msg

func (v Error) Msg() string

func (Error) ServiceCode

func (Error) ServiceCode() int

func (Error) StatusCode

func (v Error) StatusCode() int

func (Error) StatusErr

func (v Error) StatusErr() *statusx.StatusErr

func (Error) Unwrap

func (v Error) Unwrap() error

type Jwt

type Jwt struct {
	Issuer  string         `env:""`
	ExpIn   types.Duration `env:""`
	SignKey string         `env:""`
}

func ConfFromContext

func ConfFromContext(ctx context.Context) (*Jwt, bool)

func MustConfFromContext

func MustConfFromContext(ctx context.Context) *Jwt

func (*Jwt) ExpiresAt added in v1.3.1

func (c *Jwt) ExpiresAt() *jwt.NumericDate

func (*Jwt) GenerateTokenByPayload

func (c *Jwt) GenerateTokenByPayload(payload interface{}) (string, error)

func (*Jwt) GenerateTokenWithoutExpByPayload added in v1.1.0

func (c *Jwt) GenerateTokenWithoutExpByPayload(payload interface{}) (string, error)

func (*Jwt) Init

func (c *Jwt) Init()

func (*Jwt) ParseToken

func (c *Jwt) ParseToken(v string) (*Claims, error)

func (*Jwt) SetDefault

func (c *Jwt) SetDefault()

type SigningMethod

type SigningMethod uint8
const (
	SIGNING_METHOD_UNKNOWN SigningMethod = iota
	SIGNING_METHOD__ECDSA256
	SIGNING_METHOD__ECDSA384
	SIGNING_METHOD__ECDSA512
	SIGNING_METHOD__HMAC256
	SIGNING_METHOD__HMAC384
	SIGNING_METHOD__HMAC512
	SIGNING_METHOD__RSA256
	SIGNING_METHOD__RSA384
	SIGNING_METHOD__RSA512
	SIGNING_METHOD__RSAPSS256
	SIGNING_METHOD__RSAPSS384
	SIGNING_METHOD__RSAPSS512
)

func ParseSigningMethodFromLabel

func ParseSigningMethodFromLabel(s string) (SigningMethod, error)

func ParseSigningMethodFromString

func ParseSigningMethodFromString(s string) (SigningMethod, error)

func (SigningMethod) ConstValues

func (v SigningMethod) ConstValues() []enum.IntStringerEnum

func (SigningMethod) Int

func (v SigningMethod) Int() int

func (SigningMethod) Label

func (v SigningMethod) Label() string

func (SigningMethod) MarshalText

func (v SigningMethod) MarshalText() ([]byte, error)

func (*SigningMethod) Scan

func (v *SigningMethod) Scan(src interface{}) error

func (SigningMethod) String

func (v SigningMethod) String() string

func (SigningMethod) TypeName

func (v SigningMethod) TypeName() string

func (*SigningMethod) UnmarshalText

func (v *SigningMethod) UnmarshalText(data []byte) error

func (SigningMethod) Value

func (v SigningMethod) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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