authpkg

package
v0.3.25 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: Apache-2.0 Imports: 22 Imported by: 6

README

auth

jwt auth

protobuf

kratos proto client ./kratos/auth/*.proto

Documentation

Index

Constants

View Source
const (
	AccessTokenExpire   = time.Hour * 24
	RefreshTokenExpire  = time.Hour * 24 * 7
	PreviousTokenExpire = time.Minute * 10

	AuthorizationKey = "Authorization"
	BearerWord       = "Bearer"
	BearerFormat     = "Bearer %s"

	PayloadIdentifierPrefixDefault = "default_"
	PayloadIdentifierPrefixUser    = "user_"
	PayloadIdentifierPrefixAdmin   = "admin_"
)

Variables

View Source
var (
	ERROR_name = map[int32]string{
		0:    "UNKNOWN",
		1001: "TOKEN_MISSING",
		1002: "TOKEN_KEY_MISSING",
		1003: "TOKEN_METHOD_MISSING",
		1004: "UNAUTHORIZED",
		1005: "TOKEN_EXPIRED",
		1006: "AUTHENTICATION_FAILED",
		1007: "TOKEN_INVALID",
		1008: "TOKEN_DEPRECATED",
		1009: "TOKEN_NOT_IN_WHITELIST",
		1010: "VERIFICATION_FAILED",
		1011: "INVALID_CLAIMS",
	}
	ERROR_value = map[string]int32{
		"UNKNOWN":                0,
		"TOKEN_MISSING":          1001,
		"TOKEN_KEY_MISSING":      1002,
		"TOKEN_METHOD_MISSING":   1003,
		"UNAUTHORIZED":           1004,
		"TOKEN_EXPIRED":          1005,
		"AUTHENTICATION_FAILED":  1006,
		"TOKEN_INVALID":          1007,
		"TOKEN_DEPRECATED":       1008,
		"TOKEN_NOT_IN_WHITELIST": 1009,
		"VERIFICATION_FAILED":    1010,
		"INVALID_CLAIMS":         1011,
	}
)

Enum value maps for ERROR.

View Source
var (
	LoginPlatformEnum_LoginPlatform_name = map[int32]string{
		0: "UNSPECIFIED",
		1: "COMPUTER",
		2: "ANDROID",
		3: "IOS",
		4: "IPAD",
	}
	LoginPlatformEnum_LoginPlatform_value = map[string]int32{
		"UNSPECIFIED": 0,
		"COMPUTER":    1,
		"ANDROID":     2,
		"IOS":         3,
		"IPAD":        4,
	}
)

Enum value maps for LoginPlatformEnum_LoginPlatform.

View Source
var (
	LoginTypeEnum_LoginType_name = map[int32]string{
		0: "UNSPECIFIED",
		1: "PHONE_AND_CAPTCHA",
		2: "PHONE_AND_PASSWORD",
		3: "EMAIL_AND_CAPTCHA",
		4: "EMAIL_AND_PASSWORD",
		5: "USERNAME_AND_PASSWORD",
		6: "WECHAT_QRCODE",
		7: "GOOGLE_OAUTH",
	}
	LoginTypeEnum_LoginType_value = map[string]int32{
		"UNSPECIFIED":           0,
		"PHONE_AND_CAPTCHA":     1,
		"PHONE_AND_PASSWORD":    2,
		"EMAIL_AND_CAPTCHA":     3,
		"EMAIL_AND_PASSWORD":    4,
		"USERNAME_AND_PASSWORD": 5,
		"WECHAT_QRCODE":         6,
		"GOOGLE_OAUTH":          7,
	}
)

Enum value maps for LoginTypeEnum_LoginType.

View Source
var (
	LoginLimitEnum_LoginLimit_name = map[int32]string{
		0: "UNLIMITED",
		1: "ONLY_ONE",
		2: "PLATFORM_ONE",
	}
	LoginLimitEnum_LoginLimit_value = map[string]int32{
		"UNLIMITED":    0,
		"ONLY_ONE":     1,
		"PLATFORM_ONE": 2,
	}
)

Enum value maps for LoginLimitEnum_LoginLimit.

View Source
var (
	TokenTypeEnum_TokenType_name = map[int32]string{
		0: "UNSPECIFIED",
		1: "ADMIN",
		2: "USER",
	}
	TokenTypeEnum_TokenType_value = map[string]int32{
		"UNSPECIFIED": 0,
		"ADMIN":       1,
		"USER":        2,
	}
)

Enum value maps for TokenTypeEnum_TokenType.

View Source
var ERROR_http_code = map[string]int{

	"UNKNOWN":                401,
	"TOKEN_MISSING":          401,
	"TOKEN_KEY_MISSING":      401,
	"TOKEN_METHOD_MISSING":   401,
	"UNAUTHORIZED":           401,
	"TOKEN_EXPIRED":          401,
	"AUTHENTICATION_FAILED":  401,
	"TOKEN_INVALID":          401,
	"TOKEN_DEPRECATED":       401,
	"TOKEN_NOT_IN_WHITELIST": 401,
	"VERIFICATION_FAILED":    401,
	"INVALID_CLAIMS":         401,
}
View Source
var File_kratos_auth_auth_kit_proto protoreflect.FileDescriptor

Functions

func CheckAndCorrectAuthClaims

func CheckAndCorrectAuthClaims(authClaims *Claims)

CheckAndCorrectAuthClaims ...

func Client

func Client(customKeyFunc KeyFunc, opts ...Option) middleware.Middleware

Client is a client jwt middleware.

func DefaultErrorAuthenticationFailed added in v0.2.17

func DefaultErrorAuthenticationFailed() *errors.Error

func DefaultErrorInvalidClaims added in v0.2.17

func DefaultErrorInvalidClaims() *errors.Error

func DefaultErrorTokenDeprecated added in v0.2.17

func DefaultErrorTokenDeprecated() *errors.Error

func DefaultErrorTokenExpired added in v0.2.17

func DefaultErrorTokenExpired() *errors.Error

func DefaultErrorTokenInvalid added in v0.2.17

func DefaultErrorTokenInvalid() *errors.Error

func DefaultErrorTokenKeyMissing added in v0.2.17

func DefaultErrorTokenKeyMissing() *errors.Error

func DefaultErrorTokenMethodMissing added in v0.2.17

func DefaultErrorTokenMethodMissing() *errors.Error

func DefaultErrorTokenMissing added in v0.2.17

func DefaultErrorTokenMissing() *errors.Error

func DefaultErrorTokenNotInWhitelist added in v0.2.17

func DefaultErrorTokenNotInWhitelist() *errors.Error

func DefaultErrorUnauthorized added in v0.2.17

func DefaultErrorUnauthorized() *errors.Error

func DefaultErrorUnknown added in v0.2.17

func DefaultErrorUnknown() *errors.Error

func DefaultErrorVerificationFailed added in v0.2.17

func DefaultErrorVerificationFailed() *errors.Error

func DefaultExpireTime

func DefaultExpireTime() *jwt.NumericDate

DefaultExpireTime 令牌过期时间

func ErrBlacklist

func ErrBlacklist() *errors.Error

func ErrGetKey

func ErrGetKey() *errors.Error

func ErrInvalidAuthToken

func ErrInvalidAuthToken() *errors.Error

func ErrInvalidClaims

func ErrInvalidClaims() *errors.Error

func ErrMissingSignKeyFunc

func ErrMissingSignKeyFunc() *errors.Error

func ErrMissingToken

func ErrMissingToken() *errors.Error

func ErrNeedTokenProvider

func ErrNeedTokenProvider() *errors.Error

func ErrSignToken

func ErrSignToken() *errors.Error

func ErrTokenExpired

func ErrTokenExpired() *errors.Error

func ErrTokenInvalid

func ErrTokenInvalid() *errors.Error

func ErrTokenParseFail

func ErrTokenParseFail() *errors.Error

func ErrUnSupportSigningMethod

func ErrUnSupportSigningMethod() *errors.Error

func ErrWhitelist

func ErrWhitelist() *errors.Error

func ErrWrongContext

func ErrWrongContext() *errors.Error

func ErrorAuthenticationFailed

func ErrorAuthenticationFailed(format string, args ...interface{}) *errors.Error

func ErrorInvalidClaims

func ErrorInvalidClaims(format string, args ...interface{}) *errors.Error

func ErrorTokenDeprecated

func ErrorTokenDeprecated(format string, args ...interface{}) *errors.Error

func ErrorTokenExpired

func ErrorTokenExpired(format string, args ...interface{}) *errors.Error

func ErrorTokenInvalid

func ErrorTokenInvalid(format string, args ...interface{}) *errors.Error

func ErrorTokenKeyMissing

func ErrorTokenKeyMissing(format string, args ...interface{}) *errors.Error

func ErrorTokenMethodMissing

func ErrorTokenMethodMissing(format string, args ...interface{}) *errors.Error

func ErrorTokenMissing

func ErrorTokenMissing(format string, args ...interface{}) *errors.Error

func ErrorTokenNotInWhitelist

func ErrorTokenNotInWhitelist(format string, args ...interface{}) *errors.Error

func ErrorUnauthorized

func ErrorUnauthorized(format string, args ...interface{}) *errors.Error

func ErrorUnknown

func ErrorUnknown(format string, args ...interface{}) *errors.Error

func ErrorVerificationFailed

func ErrorVerificationFailed(format string, args ...interface{}) *errors.Error

func GenExpireAt

func GenExpireAt(duration time.Duration) *jwt.NumericDate

GenExpireAt ...

func Is

func Is(err, target error) bool

Is ...

func IsAuthenticationFailed

func IsAuthenticationFailed(err error) bool

func IsInvalidClaims

func IsInvalidClaims(err error) bool

func IsTokenDeprecated

func IsTokenDeprecated(err error) bool

func IsTokenExpired

func IsTokenExpired(err error) bool

func IsTokenInvalid

func IsTokenInvalid(err error) bool

func IsTokenKeyMissing

func IsTokenKeyMissing(err error) bool

func IsTokenMethodMissing

func IsTokenMethodMissing(err error) bool

func IsTokenMissing

func IsTokenMissing(err error) bool

func IsTokenNotInWhitelist

func IsTokenNotInWhitelist(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

func IsUnknown

func IsUnknown(err error) bool

func IsVerificationFailed

func IsVerificationFailed(err error) bool

func PutAuthClaimsIntoContext

func PutAuthClaimsIntoContext(ctx context.Context, info jwt.Claims) context.Context

PutAuthClaimsIntoContext put auth info into context

func Server

func Server(signKeyFunc KeyFunc, opts ...Option) middleware.Middleware

Server is a server auth middleware. Check the token and extract the info from token.

Types

type AccessTokenValidateFunc

type AccessTokenValidateFunc func(context.Context, *Claims) error

AccessTokenValidateFunc 自定义验证

type AuthCacheKeyPrefix

type AuthCacheKeyPrefix struct {
	TokensKeyPrefix     RedisCacheKeyPrefix // 用户令牌
	BlackTokenKeyPrefix RedisCacheKeyPrefix // 黑名单
	LimitTokenKeyPrefix RedisCacheKeyPrefix // 登录限制
	ClearTokenKeyPrefix RedisCacheKeyPrefix // 清除token
}

AuthCacheKeyPrefix ...

func CheckAuthCacheKeyPrefix

func CheckAuthCacheKeyPrefix(inputKeyPrefix *AuthCacheKeyPrefix) *AuthCacheKeyPrefix

CheckAuthCacheKeyPrefix ...

type AuthRepo

type AuthRepo interface {
	JWTSigningKeyFunc(ctx context.Context) jwt.Keyfunc
	JWTSigningMethod() jwt.SigningMethod
	JWTSigningClaims() jwt.Claims

	// SignToken 签证Token
	// @Param signKey 拼接在原来的signKey上
	SignToken(ctx context.Context, authClaims *Claims) (*TokenResponse, error)
	RefreshToken(ctx context.Context, originRefreshClaims *Claims) (*TokenResponse, error)

	DecodeAccessToken(ctx context.Context, accessToken string) (*Claims, error)
	DecodeRefreshToken(ctx context.Context, refreshToken string) (*Claims, error)

	VerifyAccessToken(ctx context.Context, authClaims *Claims) error
	VerifyRefreshToken(ctx context.Context, authClaims *Claims) error
}

AuthRepo ...

func NewAuthRepo

func NewAuthRepo(config Config, logger log.Logger, tokenManger TokenManger) (AuthRepo, error)

NewAuthRepo ...

type Claims

type Claims struct {
	jwt.RegisteredClaims

	// payload 授权信息
	Payload *Payload `json:"p,omitempty"`
}

Claims jwt.Claims

func GenAuthClaimsByAuthClaims

func GenAuthClaimsByAuthClaims(authClaims *Claims, accessTokenExpire time.Duration) *Claims

GenAuthClaimsByAuthClaims ...

func GenAuthClaimsByAuthPayload

func GenAuthClaimsByAuthPayload(payload *Payload, accessTokenExpire time.Duration) *Claims

GenAuthClaimsByAuthPayload ...

func GenRefreshClaimsByAuthClaims

func GenRefreshClaimsByAuthClaims(authClaims *Claims, refreshTokenExpire time.Duration) *Claims

GenRefreshClaimsByAuthClaims ...

func GetAuthClaimsFromContext

func GetAuthClaimsFromContext(ctx context.Context) (*Claims, bool)

GetAuthClaimsFromContext extract auth info from context

func (*Claims) DecodeString

func (s *Claims) DecodeString(claimCiphertext string) error

DecodeString ...

func (*Claims) EncodeToString

func (s *Claims) EncodeToString() (string, error)

EncodeToString ...

type Config

type Config struct {
	SignCrypto    SignEncryptor
	RefreshCrypto RefreshEncryptor

	AccessTokenExpire   time.Duration
	RefreshTokenExpire  time.Duration
	PreviousTokenExpire time.Duration
}

Config ...

type ERROR

type ERROR int32

ERROR ...

const (
	ERROR_UNKNOWN                ERROR = 0
	ERROR_TOKEN_MISSING          ERROR = 1001
	ERROR_TOKEN_KEY_MISSING      ERROR = 1002
	ERROR_TOKEN_METHOD_MISSING   ERROR = 1003
	ERROR_UNAUTHORIZED           ERROR = 1004
	ERROR_TOKEN_EXPIRED          ERROR = 1005
	ERROR_AUTHENTICATION_FAILED  ERROR = 1006
	ERROR_TOKEN_INVALID          ERROR = 1007
	ERROR_TOKEN_DEPRECATED       ERROR = 1008
	ERROR_TOKEN_NOT_IN_WHITELIST ERROR = 1009
	ERROR_VERIFICATION_FAILED    ERROR = 1010
	ERROR_INVALID_CLAIMS         ERROR = 1011
)

func (ERROR) Descriptor

func (ERROR) Descriptor() protoreflect.EnumDescriptor

func (ERROR) Enum

func (x ERROR) Enum() *ERROR

func (ERROR) EnumDescriptor deprecated

func (ERROR) EnumDescriptor() ([]byte, []int)

Deprecated: Use ERROR.Descriptor instead.

func (ERROR) HTTPCode added in v0.2.17

func (x ERROR) HTTPCode() int

func (ERROR) Number

func (x ERROR) Number() protoreflect.EnumNumber

func (ERROR) String

func (x ERROR) String() string

func (ERROR) Type

func (ERROR) Type() protoreflect.EnumType

type KeyFunc

type KeyFunc func(context.Context) jwt.Keyfunc

KeyFunc 自定义 jwt.Keyfunc

type LoginLimitEnum

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

func (*LoginLimitEnum) Descriptor deprecated

func (*LoginLimitEnum) Descriptor() ([]byte, []int)

Deprecated: Use LoginLimitEnum.ProtoReflect.Descriptor instead.

func (*LoginLimitEnum) ProtoMessage

func (*LoginLimitEnum) ProtoMessage()

func (*LoginLimitEnum) ProtoReflect

func (x *LoginLimitEnum) ProtoReflect() protoreflect.Message

func (*LoginLimitEnum) Reset

func (x *LoginLimitEnum) Reset()

func (*LoginLimitEnum) String

func (x *LoginLimitEnum) String() string

type LoginLimitEnum_LoginLimit

type LoginLimitEnum_LoginLimit int32
const (
	LoginLimitEnum_UNLIMITED    LoginLimitEnum_LoginLimit = 0
	LoginLimitEnum_ONLY_ONE     LoginLimitEnum_LoginLimit = 1
	LoginLimitEnum_PLATFORM_ONE LoginLimitEnum_LoginLimit = 2
)

func (LoginLimitEnum_LoginLimit) Descriptor

func (LoginLimitEnum_LoginLimit) Enum

func (LoginLimitEnum_LoginLimit) EnumDescriptor deprecated

func (LoginLimitEnum_LoginLimit) EnumDescriptor() ([]byte, []int)

Deprecated: Use LoginLimitEnum_LoginLimit.Descriptor instead.

func (LoginLimitEnum_LoginLimit) Number

func (LoginLimitEnum_LoginLimit) String

func (x LoginLimitEnum_LoginLimit) String() string

func (LoginLimitEnum_LoginLimit) Type

type LoginPlatformEnum

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

func (*LoginPlatformEnum) Descriptor deprecated

func (*LoginPlatformEnum) Descriptor() ([]byte, []int)

Deprecated: Use LoginPlatformEnum.ProtoReflect.Descriptor instead.

func (*LoginPlatformEnum) ProtoMessage

func (*LoginPlatformEnum) ProtoMessage()

func (*LoginPlatformEnum) ProtoReflect

func (x *LoginPlatformEnum) ProtoReflect() protoreflect.Message

func (*LoginPlatformEnum) Reset

func (x *LoginPlatformEnum) Reset()

func (*LoginPlatformEnum) String

func (x *LoginPlatformEnum) String() string

type LoginPlatformEnum_LoginPlatform

type LoginPlatformEnum_LoginPlatform int32
const (
	// UNSPECIFIED 未指定
	LoginPlatformEnum_UNSPECIFIED LoginPlatformEnum_LoginPlatform = 0
	LoginPlatformEnum_COMPUTER    LoginPlatformEnum_LoginPlatform = 1
	LoginPlatformEnum_ANDROID     LoginPlatformEnum_LoginPlatform = 2
	LoginPlatformEnum_IOS         LoginPlatformEnum_LoginPlatform = 3
	LoginPlatformEnum_IPAD        LoginPlatformEnum_LoginPlatform = 4
)

func (LoginPlatformEnum_LoginPlatform) Descriptor

func (LoginPlatformEnum_LoginPlatform) Enum

func (LoginPlatformEnum_LoginPlatform) EnumDescriptor deprecated

func (LoginPlatformEnum_LoginPlatform) EnumDescriptor() ([]byte, []int)

Deprecated: Use LoginPlatformEnum_LoginPlatform.Descriptor instead.

func (LoginPlatformEnum_LoginPlatform) Number

func (LoginPlatformEnum_LoginPlatform) String

func (LoginPlatformEnum_LoginPlatform) Type

type LoginTypeEnum

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

func (*LoginTypeEnum) Descriptor deprecated

func (*LoginTypeEnum) Descriptor() ([]byte, []int)

Deprecated: Use LoginTypeEnum.ProtoReflect.Descriptor instead.

func (*LoginTypeEnum) ProtoMessage

func (*LoginTypeEnum) ProtoMessage()

func (*LoginTypeEnum) ProtoReflect

func (x *LoginTypeEnum) ProtoReflect() protoreflect.Message

func (*LoginTypeEnum) Reset

func (x *LoginTypeEnum) Reset()

func (*LoginTypeEnum) String

func (x *LoginTypeEnum) String() string

type LoginTypeEnum_LoginType

type LoginTypeEnum_LoginType int32
const (
	// UNSPECIFIED 未指定
	LoginTypeEnum_UNSPECIFIED           LoginTypeEnum_LoginType = 0
	LoginTypeEnum_PHONE_AND_CAPTCHA     LoginTypeEnum_LoginType = 1
	LoginTypeEnum_PHONE_AND_PASSWORD    LoginTypeEnum_LoginType = 2
	LoginTypeEnum_EMAIL_AND_CAPTCHA     LoginTypeEnum_LoginType = 3
	LoginTypeEnum_EMAIL_AND_PASSWORD    LoginTypeEnum_LoginType = 4
	LoginTypeEnum_USERNAME_AND_PASSWORD LoginTypeEnum_LoginType = 5
	LoginTypeEnum_WECHAT_QRCODE         LoginTypeEnum_LoginType = 6
	LoginTypeEnum_GOOGLE_OAUTH          LoginTypeEnum_LoginType = 7
)

func (LoginTypeEnum_LoginType) Descriptor

func (LoginTypeEnum_LoginType) Enum

func (LoginTypeEnum_LoginType) EnumDescriptor deprecated

func (LoginTypeEnum_LoginType) EnumDescriptor() ([]byte, []int)

Deprecated: Use LoginTypeEnum_LoginType.Descriptor instead.

func (LoginTypeEnum_LoginType) Number

func (LoginTypeEnum_LoginType) String

func (x LoginTypeEnum_LoginType) String() string

func (LoginTypeEnum_LoginType) Type

type Option

type Option func(*options)

Option is jwt option.

func WithAccessTokenHeader

func WithAccessTokenHeader(header map[string]interface{}) Option

WithAccessTokenHeader withe customer accessTokenHeader for client side

func WithAccessTokenValidator

func WithAccessTokenValidator(tokenValidator AccessTokenValidateFunc) Option

WithAccessTokenValidator token验证

func WithClaims

func WithClaims(f func() jwt.Claims) Option

WithClaims with customer claim If you use it in Server, f needs to return a new jwt.Claims object each time to avoid concurrent write problems If you use it in Client, f only needs to return a single object to provide performance

func WithSigningMethod

func WithSigningMethod(method jwt.SigningMethod) Option

WithSigningMethod with signing method option.

type Payload

type Payload struct {
	// TokenId 令牌唯一id
	TokenID string `json:"ti,omitempty"`
	// uid 用户唯一id
	UserID uint64 `json:"uid,omitempty"`
	// UserUuid 用户唯一id
	UserUuid string `json:"uuid,omitempty"`
	// LoginPlatform 登录平台信息
	LoginPlatform LoginPlatformEnum_LoginPlatform `json:"lp,omitempty"`
	// LoginType 登录类型
	LoginType LoginTypeEnum_LoginType `json:"lt,omitempty"`
	// LoginLimit 登录限制
	LoginLimit LoginLimitEnum_LoginLimit `json:"ll,omitempty"`
	// TokenType 令牌类型
	TokenType TokenTypeEnum_TokenType `json:"tt,omitempty"`
}

Payload 授权信息

func (*Payload) UserIdentifier

func (s *Payload) UserIdentifier() string

UserIdentifier ...

type RedisCacheKeyPrefix

type RedisCacheKeyPrefix string

RedisCacheKeyPrefix ...

const (
	DefaultBlackTokenKeyPrefix RedisCacheKeyPrefix = "kit:auth_black:"
	DefaultLoginLimitKeyPrefix RedisCacheKeyPrefix = "kit:auth_limit:"
	DefaultAuthTokenKeyPrefix  RedisCacheKeyPrefix = "kit:auth_token:"
	DefaultClearTokenKeyPrefix RedisCacheKeyPrefix = "kit:auth_clear:"
)

func (RedisCacheKeyPrefix) String

func (s RedisCacheKeyPrefix) String() string

type RefreshEncryptor

type RefreshEncryptor interface {
	EncryptToken(ctx context.Context, refreshClaims *Claims) (string, error)
	DecryptToken(ctx context.Context, refreshToken string) (*Claims, error)
}

RefreshEncryptor ...

func NewCBCCipher

func NewCBCCipher(key string) RefreshEncryptor

NewCBCCipher ...

type SignEncryptor

type SignEncryptor interface {
	JWTSigningKeyFunc(ctx context.Context) jwt.Keyfunc
	JWTSigningMethod() jwt.SigningMethod
	JWTSigningClaims() jwt.Claims

	EncryptToken(ctx context.Context, authClaims *Claims) (string, error)
	DecryptToken(ctx context.Context, accessToken string) (*Claims, error)
}

SignEncryptor ...

func NewSignEncryptor

func NewSignEncryptor(key string) SignEncryptor

NewSignEncryptor ...

type TokenItem

type TokenItem struct {
	TokenID        string `json:"ti,omitempty"`
	RefreshTokenID string `json:"rti,omitempty"`
	ExpiredAt      int64  `json:"ea,omitempty"`
	IsRefreshToken bool   `json:"ift,omitempty"`

	// payload 授权信息
	Payload *Payload `json:"p,omitempty"`
}

TokenItem 令牌信息

func (*TokenItem) DecodeString

func (s *TokenItem) DecodeString(tokenItem string) error

DecodeString ...

func (*TokenItem) EncodeToString

func (s *TokenItem) EncodeToString() (string, error)

EncodeToString ...

type TokenManger

type TokenManger interface {
	SaveAccessTokens(ctx context.Context, userIdentifier string, tokenItems []*TokenItem) error
	ResetPreviousTokens(ctx context.Context, userIdentifier string, tokenItems []*TokenItem) error
	AddBlacklist(ctx context.Context, userIdentifier string, tokenItems []*TokenItem) error
	AddLoginLimit(ctx context.Context, tokenItems []*TokenItem) error

	GetToken(ctx context.Context, userIdentifier string, tokenID string) (item *TokenItem, isNotFound bool, err error)
	GetAllTokens(ctx context.Context, userIdentifier string) (map[string]*TokenItem, error)

	DeleteTokens(ctx context.Context, userIdentifier string, tokenItems []*TokenItem) error
	DeleteExpireTokens(ctx context.Context, userIdentifier string) error

	IsLoginLimit(ctx context.Context, tokenID string) (bool, LoginLimitEnum_LoginLimit, error)
	IsExistToken(ctx context.Context, userIdentifier string, tokenID string) (bool, error)
	IsBlacklist(ctx context.Context, tokenID string) (bool, error)

	// EasyLock 简单锁,等待解锁或者锁定时间过期后自动解锁
	EasyLock(ctx context.Context, lockName string) (lockerpkg.Unlocker, error)
}

TokenManger ...

func NewTokenManger

func NewTokenManger(
	logger log.Logger,
	redisCC redis.UniversalClient,
	authCacheKeyPrefix *AuthCacheKeyPrefix,
) TokenManger

NewTokenManger ...

type TokenResponse

type TokenResponse struct {
	AccessToken  string
	RefreshToken string

	AccessTokenItem  *TokenItem
	RefreshTokenItem *TokenItem
}

TokenResponse ...

type TokenTypeEnum

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

func (*TokenTypeEnum) Descriptor deprecated

func (*TokenTypeEnum) Descriptor() ([]byte, []int)

Deprecated: Use TokenTypeEnum.ProtoReflect.Descriptor instead.

func (*TokenTypeEnum) ProtoMessage

func (*TokenTypeEnum) ProtoMessage()

func (*TokenTypeEnum) ProtoReflect

func (x *TokenTypeEnum) ProtoReflect() protoreflect.Message

func (*TokenTypeEnum) Reset

func (x *TokenTypeEnum) Reset()

func (*TokenTypeEnum) String

func (x *TokenTypeEnum) String() string

type TokenTypeEnum_TokenType

type TokenTypeEnum_TokenType int32
const (
	TokenTypeEnum_UNSPECIFIED TokenTypeEnum_TokenType = 0
	TokenTypeEnum_ADMIN       TokenTypeEnum_TokenType = 1
	TokenTypeEnum_USER        TokenTypeEnum_TokenType = 2
)

func (TokenTypeEnum_TokenType) Descriptor

func (TokenTypeEnum_TokenType) Enum

func (TokenTypeEnum_TokenType) EnumDescriptor deprecated

func (TokenTypeEnum_TokenType) EnumDescriptor() ([]byte, []int)

Deprecated: Use TokenTypeEnum_TokenType.Descriptor instead.

func (TokenTypeEnum_TokenType) Number

func (TokenTypeEnum_TokenType) String

func (x TokenTypeEnum_TokenType) String() string

func (TokenTypeEnum_TokenType) Type

Jump to

Keyboard shortcuts

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