Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAndCorrectAuthClaims(authClaims *Claims)
- func Client(customKeyFunc KeyFunc, opts ...Option) middleware.Middleware
- func DefaultErrorAuthenticationFailed() *errors.Error
- func DefaultErrorInvalidClaims() *errors.Error
- func DefaultErrorTokenDeprecated() *errors.Error
- func DefaultErrorTokenExpired() *errors.Error
- func DefaultErrorTokenInvalid() *errors.Error
- func DefaultErrorTokenKeyMissing() *errors.Error
- func DefaultErrorTokenMethodMissing() *errors.Error
- func DefaultErrorTokenMissing() *errors.Error
- func DefaultErrorTokenNotInWhitelist() *errors.Error
- func DefaultErrorUnauthorized() *errors.Error
- func DefaultErrorUnknown() *errors.Error
- func DefaultErrorVerificationFailed() *errors.Error
- func DefaultExpireTime() *jwt.NumericDate
- func ErrBlacklist() *errors.Error
- func ErrGetKey() *errors.Error
- func ErrInvalidAuthToken() *errors.Error
- func ErrInvalidClaims() *errors.Error
- func ErrMissingSignKeyFunc() *errors.Error
- func ErrMissingToken() *errors.Error
- func ErrNeedTokenProvider() *errors.Error
- func ErrSignToken() *errors.Error
- func ErrTokenExpired() *errors.Error
- func ErrTokenInvalid() *errors.Error
- func ErrTokenParseFail() *errors.Error
- func ErrUnSupportSigningMethod() *errors.Error
- func ErrWhitelist() *errors.Error
- func ErrWrongContext() *errors.Error
- func ErrorAuthenticationFailed(format string, args ...interface{}) *errors.Error
- func ErrorInvalidClaims(format string, args ...interface{}) *errors.Error
- func ErrorTokenDeprecated(format string, args ...interface{}) *errors.Error
- func ErrorTokenExpired(format string, args ...interface{}) *errors.Error
- func ErrorTokenInvalid(format string, args ...interface{}) *errors.Error
- func ErrorTokenKeyMissing(format string, args ...interface{}) *errors.Error
- func ErrorTokenMethodMissing(format string, args ...interface{}) *errors.Error
- func ErrorTokenMissing(format string, args ...interface{}) *errors.Error
- func ErrorTokenNotInWhitelist(format string, args ...interface{}) *errors.Error
- func ErrorUnauthorized(format string, args ...interface{}) *errors.Error
- func ErrorUnknown(format string, args ...interface{}) *errors.Error
- func ErrorVerificationFailed(format string, args ...interface{}) *errors.Error
- func GenExpireAt(duration time.Duration) *jwt.NumericDate
- func Is(err, target error) bool
- func IsAuthenticationFailed(err error) bool
- func IsInvalidClaims(err error) bool
- func IsTokenDeprecated(err error) bool
- func IsTokenExpired(err error) bool
- func IsTokenInvalid(err error) bool
- func IsTokenKeyMissing(err error) bool
- func IsTokenMethodMissing(err error) bool
- func IsTokenMissing(err error) bool
- func IsTokenNotInWhitelist(err error) bool
- func IsUnauthorized(err error) bool
- func IsUnknown(err error) bool
- func IsVerificationFailed(err error) bool
- func PutAuthClaimsIntoContext(ctx context.Context, info jwt.Claims) context.Context
- func Server(signKeyFunc KeyFunc, opts ...Option) middleware.Middleware
- type AccessTokenValidateFunc
- type AuthCacheKeyPrefix
- type AuthRepo
- type Claims
- func GenAuthClaimsByAuthClaims(authClaims *Claims, accessTokenExpire time.Duration) *Claims
- func GenAuthClaimsByAuthPayload(payload *Payload, accessTokenExpire time.Duration) *Claims
- func GenRefreshClaimsByAuthClaims(authClaims *Claims, refreshTokenExpire time.Duration) *Claims
- func GetAuthClaimsFromContext(ctx context.Context) (*Claims, bool)
- type Config
- type ERROR
- type KeyFunc
- type LoginLimitEnum
- type LoginLimitEnum_LoginLimit
- func (LoginLimitEnum_LoginLimit) Descriptor() protoreflect.EnumDescriptor
- func (x LoginLimitEnum_LoginLimit) Enum() *LoginLimitEnum_LoginLimit
- func (LoginLimitEnum_LoginLimit) EnumDescriptor() ([]byte, []int)deprecated
- func (x LoginLimitEnum_LoginLimit) Number() protoreflect.EnumNumber
- func (x LoginLimitEnum_LoginLimit) String() string
- func (LoginLimitEnum_LoginLimit) Type() protoreflect.EnumType
- type LoginPlatformEnum
- type LoginPlatformEnum_LoginPlatform
- func (LoginPlatformEnum_LoginPlatform) Descriptor() protoreflect.EnumDescriptor
- func (x LoginPlatformEnum_LoginPlatform) Enum() *LoginPlatformEnum_LoginPlatform
- func (LoginPlatformEnum_LoginPlatform) EnumDescriptor() ([]byte, []int)deprecated
- func (x LoginPlatformEnum_LoginPlatform) Number() protoreflect.EnumNumber
- func (x LoginPlatformEnum_LoginPlatform) String() string
- func (LoginPlatformEnum_LoginPlatform) Type() protoreflect.EnumType
- type LoginTypeEnum
- type LoginTypeEnum_LoginType
- func (LoginTypeEnum_LoginType) Descriptor() protoreflect.EnumDescriptor
- func (x LoginTypeEnum_LoginType) Enum() *LoginTypeEnum_LoginType
- func (LoginTypeEnum_LoginType) EnumDescriptor() ([]byte, []int)deprecated
- func (x LoginTypeEnum_LoginType) Number() protoreflect.EnumNumber
- func (x LoginTypeEnum_LoginType) String() string
- func (LoginTypeEnum_LoginType) Type() protoreflect.EnumType
- type Option
- type Payload
- type RedisCacheKeyPrefix
- type RefreshEncryptor
- type SignEncryptor
- type TokenItem
- type TokenManger
- type TokenResponse
- type TokenTypeEnum
- type TokenTypeEnum_TokenType
- func (TokenTypeEnum_TokenType) Descriptor() protoreflect.EnumDescriptor
- func (x TokenTypeEnum_TokenType) Enum() *TokenTypeEnum_TokenType
- func (TokenTypeEnum_TokenType) EnumDescriptor() ([]byte, []int)deprecated
- func (x TokenTypeEnum_TokenType) Number() protoreflect.EnumNumber
- func (x TokenTypeEnum_TokenType) String() string
- func (TokenTypeEnum_TokenType) Type() protoreflect.EnumType
Constants ¶
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 ¶
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.
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.
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.
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.
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.
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,
}
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 DefaultErrorInvalidClaims ¶ added in v0.2.17
func DefaultErrorTokenDeprecated ¶ added in v0.2.17
func DefaultErrorTokenExpired ¶ added in v0.2.17
func DefaultErrorTokenInvalid ¶ added in v0.2.17
func DefaultErrorTokenKeyMissing ¶ added in v0.2.17
func DefaultErrorTokenMethodMissing ¶ added in v0.2.17
func DefaultErrorTokenMissing ¶ added in v0.2.17
func DefaultErrorTokenNotInWhitelist ¶ added in v0.2.17
func DefaultErrorUnauthorized ¶ added in v0.2.17
func DefaultErrorUnknown ¶ added in v0.2.17
func DefaultErrorVerificationFailed ¶ added in v0.2.17
func ErrBlacklist ¶
func ErrInvalidAuthToken ¶
func ErrInvalidClaims ¶
func ErrMissingSignKeyFunc ¶
func ErrMissingToken ¶
func ErrNeedTokenProvider ¶
func ErrSignToken ¶
func ErrTokenExpired ¶
func ErrTokenInvalid ¶
func ErrTokenParseFail ¶
func ErrWhitelist ¶
func ErrWrongContext ¶
func ErrorInvalidClaims ¶
func ErrorTokenDeprecated ¶
func ErrorTokenExpired ¶
func ErrorTokenInvalid ¶
func ErrorTokenKeyMissing ¶
func ErrorTokenMethodMissing ¶
func ErrorTokenMissing ¶
func ErrorUnauthorized ¶
func ErrorUnknown ¶
func ErrorVerificationFailed ¶
func IsAuthenticationFailed ¶
func IsInvalidClaims ¶
func IsTokenDeprecated ¶
func IsTokenExpired ¶
func IsTokenInvalid ¶
func IsTokenKeyMissing ¶
func IsTokenMethodMissing ¶
func IsTokenMissing ¶
func IsTokenNotInWhitelist ¶
func IsUnauthorized ¶
func IsVerificationFailed ¶
func PutAuthClaimsIntoContext ¶
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 ¶
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 ¶
NewAuthRepo ...
type Claims ¶
type Claims struct { jwt.RegisteredClaims // payload 授权信息 Payload *Payload `json:"p,omitempty"` }
Claims jwt.Claims
func GenAuthClaimsByAuthClaims ¶
GenAuthClaimsByAuthClaims ...
func GenAuthClaimsByAuthPayload ¶
GenAuthClaimsByAuthPayload ...
func GenRefreshClaimsByAuthClaims ¶
GenRefreshClaimsByAuthClaims ...
func GetAuthClaimsFromContext ¶
GetAuthClaimsFromContext extract auth info from context
func (*Claims) DecodeString ¶
DecodeString ...
func (*Claims) EncodeToString ¶
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) EnumDescriptor
deprecated
func (ERROR) Number ¶
func (x ERROR) Number() protoreflect.EnumNumber
func (ERROR) Type ¶
func (ERROR) Type() protoreflect.EnumType
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) Descriptor() protoreflect.EnumDescriptor
func (LoginLimitEnum_LoginLimit) Enum ¶
func (x LoginLimitEnum_LoginLimit) Enum() *LoginLimitEnum_LoginLimit
func (LoginLimitEnum_LoginLimit) EnumDescriptor
deprecated
func (LoginLimitEnum_LoginLimit) EnumDescriptor() ([]byte, []int)
Deprecated: Use LoginLimitEnum_LoginLimit.Descriptor instead.
func (LoginLimitEnum_LoginLimit) Number ¶
func (x LoginLimitEnum_LoginLimit) Number() protoreflect.EnumNumber
func (LoginLimitEnum_LoginLimit) String ¶
func (x LoginLimitEnum_LoginLimit) String() string
func (LoginLimitEnum_LoginLimit) Type ¶
func (LoginLimitEnum_LoginLimit) Type() protoreflect.EnumType
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) Descriptor() protoreflect.EnumDescriptor
func (LoginPlatformEnum_LoginPlatform) Enum ¶
func (x LoginPlatformEnum_LoginPlatform) Enum() *LoginPlatformEnum_LoginPlatform
func (LoginPlatformEnum_LoginPlatform) EnumDescriptor
deprecated
func (LoginPlatformEnum_LoginPlatform) EnumDescriptor() ([]byte, []int)
Deprecated: Use LoginPlatformEnum_LoginPlatform.Descriptor instead.
func (LoginPlatformEnum_LoginPlatform) Number ¶
func (x LoginPlatformEnum_LoginPlatform) Number() protoreflect.EnumNumber
func (LoginPlatformEnum_LoginPlatform) String ¶
func (x LoginPlatformEnum_LoginPlatform) String() string
func (LoginPlatformEnum_LoginPlatform) Type ¶
func (LoginPlatformEnum_LoginPlatform) Type() protoreflect.EnumType
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) Descriptor() protoreflect.EnumDescriptor
func (LoginTypeEnum_LoginType) Enum ¶
func (x LoginTypeEnum_LoginType) Enum() *LoginTypeEnum_LoginType
func (LoginTypeEnum_LoginType) EnumDescriptor
deprecated
func (LoginTypeEnum_LoginType) EnumDescriptor() ([]byte, []int)
Deprecated: Use LoginTypeEnum_LoginType.Descriptor instead.
func (LoginTypeEnum_LoginType) Number ¶
func (x LoginTypeEnum_LoginType) Number() protoreflect.EnumNumber
func (LoginTypeEnum_LoginType) String ¶
func (x LoginTypeEnum_LoginType) String() string
func (LoginTypeEnum_LoginType) Type ¶
func (LoginTypeEnum_LoginType) Type() protoreflect.EnumType
type Option ¶
type Option func(*options)
Option is jwt option.
func WithAccessTokenHeader ¶
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 授权信息
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 ...
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 ...
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 ¶
DecodeString ...
func (*TokenItem) EncodeToString ¶
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) Descriptor() protoreflect.EnumDescriptor
func (TokenTypeEnum_TokenType) Enum ¶
func (x TokenTypeEnum_TokenType) Enum() *TokenTypeEnum_TokenType
func (TokenTypeEnum_TokenType) EnumDescriptor
deprecated
func (TokenTypeEnum_TokenType) EnumDescriptor() ([]byte, []int)
Deprecated: Use TokenTypeEnum_TokenType.Descriptor instead.
func (TokenTypeEnum_TokenType) Number ¶
func (x TokenTypeEnum_TokenType) Number() protoreflect.EnumNumber
func (TokenTypeEnum_TokenType) String ¶
func (x TokenTypeEnum_TokenType) String() string
func (TokenTypeEnum_TokenType) Type ¶
func (TokenTypeEnum_TokenType) Type() protoreflect.EnumType