auth

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecodePrivPem = errors.New("DECODE PRIVATE PEM FAIL")
	ErrDecodePubPem  = errors.New("DECODE PUBLIC PEM FAIL")
	ErrRsaKeyType    = errors.New("KEY TYPE IS NOT RSA")
	ErrTokenMethod   = errors.New("INVALID TOKEN METHOD")
	ErrTokenClaim    = errors.New("INVALID TOKEN CLAIM")
)

Functions

This section is empty.

Types

type JwtAuth

type JwtAuth struct {
	*JwtValidator
	// contains filtered or unexported fields
}

JwtAuth 用于颁发jwt授权

func NewJwtAuth

func NewJwtAuth(opts ...Option) *JwtAuth

func (*JwtAuth) GenToken

func (j *JwtAuth) GenToken(uid, ext string, refresh bool) (*TokenInfo, error)

GenToken 生成jwt token

type JwtValidator

type JwtValidator struct {
	// contains filtered or unexported fields
}

JwtValidator 用于验证jwt token

func NewJwtValidator

func NewJwtValidator(opts ...ValidateOption) *JwtValidator

func (*JwtValidator) GetToken

func (jv *JwtValidator) GetToken(token string) (*PlatoClaims, error)

GetToken 解析并获取token结构体

type Option

type Option func(options *Options)

func WithOption

func WithOption(o *Options) Option

WithOption 通过另一个Options来更新Options 注意,所有的默认值无法被更新,以防误设置

type Options

type Options struct {
	*ValidateOptions `yaml:"validate"`

	//TokenExpires token 过期时间
	TokenExpiresTime int `yaml:"token_expires_time"`
	//TokenRefreshTime token 刷新续期时间
	TokenRefreshTime int `yaml:"token_refresh_time"`
	//PrivateKeyPath 私钥路径
	PrivateKeyPath string `yaml:"private_key_path"`
}

func NewDefaultOptions

func NewDefaultOptions() *Options

type PlatoClaims

type PlatoClaims struct {
	jwt.RegisteredClaims
	Uid string `json:"uid,omitempty"`
	Ext string `json:"ext,omitempty"`
}

type TokenInfo

type TokenInfo struct {
	AccessToken  string
	RefreshToken string
}

type ValidateOption

type ValidateOption func(options *ValidateOptions)

func WithPubKeyPath

func WithPubKeyPath(path string) ValidateOption

func WithValidateOption

func WithValidateOption(o *ValidateOptions) ValidateOption

WithValidateOption 通过另一个ValidateOptions来更新ValidateOptions 注意,所有的默认值无法被更新,以防误设置

type ValidateOptions

type ValidateOptions struct {
	// PublicKeyPath 公钥路径
	PublicKeyPath string `yaml:"public_key_path"`
}

func NewDefaultValidateOptions

func NewDefaultValidateOptions() *ValidateOptions

Jump to

Keyboard shortcuts

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