auths

package
v2.10.18 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenTypeNormal  = 0 //普通token
	TokenTypeRefresh = 1 //刷新token
)

Variables

View Source
var (
	ErrInvalidToken = errors.New("invalid token")
)

Functions

func DecryptData added in v2.3.0

func DecryptData(ep *Encipherer, typ DecryptType, src string, res any) error

func EncryptData added in v2.3.0

func EncryptData(ep *Encipherer, typ EncryptType, src any) (string, error)

func EncryptDataRaw added in v2.10.18

func EncryptDataRaw(ep *Encipherer, typ EncryptType, data []byte) (string, error)

func JwtEncode added in v2.9.0

func JwtEncode(typ int, userId int64, expire time.Duration, secret string) (string, time.Time, error)

jwt encode

Types

type DecryptType added in v2.3.0

type DecryptType int
const (
	DecryptTypeAes       DecryptType //1-aes解密
	DecryptTypeRsaPrikey             //2-rsa私钥解密
	DecryptTypeRsaPubkey             //2-rsa公钥解密
	DecryptTypeNone                  //2-none
)

type Encipherer

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

func NewEncipherer

func NewEncipherer(options ...Option) *Encipherer

func (*Encipherer) AesCbcDecrypt

func (e *Encipherer) AesCbcDecrypt(data string) ([]byte, error)

func (*Encipherer) AesCbcEncrypt

func (e *Encipherer) AesCbcEncrypt(data []byte) (string, error)

func (*Encipherer) GetAesSecretKey

func (e *Encipherer) GetAesSecretKey() (string, string)

func (*Encipherer) RsaPrikeyDecrypt

func (e *Encipherer) RsaPrikeyDecrypt(data string) ([]byte, error)

func (*Encipherer) RsaPrikeyEncrypt

func (e *Encipherer) RsaPrikeyEncrypt(data []byte) (string, error)

func (*Encipherer) RsaPubkeyDecrypt

func (e *Encipherer) RsaPubkeyDecrypt(data string) ([]byte, error)

func (*Encipherer) RsaPubkeyEncrypt

func (e *Encipherer) RsaPubkeyEncrypt(data []byte) (string, error)

type EncryptType added in v2.3.0

type EncryptType int
const (
	EncryptTypeAes       EncryptType //1-aes加密
	EncryptTypeRsaPrikey             //2-rsa私钥加密
	EncryptTypeRsaPubkey             //2-rsag公钥加密
	EncryptTypeNone                  //-none
)

type IdGenerator added in v2.8.0

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

func NewIdGenerator added in v2.8.0

func NewIdGenerator(table string, key string, idSource IdSourcer, idStore IdStorer, options ...IdOption) *IdGenerator

func (*IdGenerator) NextId added in v2.8.0

func (g *IdGenerator) NextId() (int64, error)

func (*IdGenerator) Store added in v2.8.0

func (g *IdGenerator) Store() error

type IdOption added in v2.8.1

type IdOption func(ig *IdGenerator)

func WithIdStoreTime added in v2.8.1

func WithIdStoreTime(storeTime time.Duration) IdOption

type IdSourcer added in v2.8.0

type IdSourcer func(key string) (int64, error)

type IdStorer added in v2.8.0

type IdStorer func(key string, id int64) error

type JwtClaims added in v2.9.0

type JwtClaims struct {
	Type   int   `json:"type"`    //类型 0-普通tokn 1-刷新token
	UserId int64 `json:"user_id"` //用户ID
	Start  int64 `json:"start"`   //开始时间
	Expire int64 `json:"expire"`  //过期时间
}

func JwtDecode added in v2.9.0

func JwtDecode(tokenString string, secret string) (*JwtClaims, error)

jwt decode

func NewJwtClaims added in v2.9.0

func NewJwtClaims(typ int, userId int64, expire time.Duration) (*JwtClaims, time.Time)

func (*JwtClaims) TypeRefresh added in v2.9.0

func (c *JwtClaims) TypeRefresh() bool

func (*JwtClaims) Valid added in v2.9.0

func (c *JwtClaims) Valid() error

type JwtData

type JwtData interface {
	UserId() int64
}

type JwtMiddleware

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

func NewJwtMiddleware

func NewJwtMiddleware(user JwtUser) *JwtMiddleware

func (*JwtMiddleware) GetAuthor

func (g *JwtMiddleware) GetAuthor() *jwt.GinJWTMiddleware

func (*JwtMiddleware) IdentityHandler

func (g *JwtMiddleware) IdentityHandler(c *gin.Context) interface{}

func (*JwtMiddleware) PayloadFunc

func (g *JwtMiddleware) PayloadFunc(data interface{}) jwt.MapClaims

func (*JwtMiddleware) Verifier

func (g *JwtMiddleware) Verifier(data interface{}, c *gin.Context) bool

type JwtUser

type JwtUser interface {
	Authenticator(c *gin.Context) (interface{}, error)
	// User can define own Unauthorized func.
	Unauthorized(c *gin.Context, code int, message string)
	// User can define own LoginResponse func.
	LoginResponse(c *gin.Context, code int, message string, time time.Time)
	// User can define own LogoutResponse func.
	LogoutResponse(c *gin.Context, code int)
	// User can define own RefreshResponse func.
	RefreshResponse(c *gin.Context, code int, message string, time time.Time)
}

type Option

type Option func(e *Encipherer)

func WithAesIv

func WithAesIv(aesIv string) Option

func WithAesKey

func WithAesKey(aesKey string) Option

func WithRsaPriKey

func WithRsaPriKey(priKey string) Option

func WithRsaPubKey

func WithRsaPubKey(pubKey string) Option

func WithSerializer added in v2.6.8

func WithSerializer(serializer serialize.Serializer) Option

func WithUnencrypt added in v2.9.2

func WithUnencrypt(val bool) Option

Jump to

Keyboard shortcuts

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