Documentation ¶
Index ¶
- Constants
- func AccessGenerate() oauth2.AccessGenerate
- func DelTokenCacheFromRedis(userId int64)
- func Init()
- func InitTokenGenerator() oauth2.AccessGenerate
- func InitTokenStore() oauth2.TokenStore
- func NewDatabaseTokenStore() (oauth2.TokenStore, error)
- func NewFileTokenStore(filename string) (oauth2.TokenStore, error)
- func NewJWTAccessGenerate() oauth2.AccessGenerate
- func NewMemeoryTokenStore() (oauth2.TokenStore, error)
- func NewRedisTokenStore() (oauth2.TokenStore, error)
- func NewUUIDAccessGenerate() oauth2.AccessGenerate
- func ParseToken(tokenString string) (oauth2.TokenInfo, error)
- func TokenStore() oauth2.TokenStore
- func ValidTokenCacheToRedis(userId int64)
- type Authentication
- type DatabaseTokenStore
- func (s *DatabaseTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
- func (s *DatabaseTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
- func (s *DatabaseTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
- func (s *DatabaseTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
- func (s *DatabaseTokenStore) GetToken(ctx context.Context, key string) (oauth2.TokenInfo, error)
- func (s *DatabaseTokenStore) RemoveByAccess(ctx context.Context, access string) error
- func (s *DatabaseTokenStore) RemoveByCode(ctx context.Context, code string) error
- func (s *DatabaseTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
- type ITokenResolver
- type ITokenStore
- type JWTTokenGenerator
- type JWTTokenResolver
- type OAuth2Token
- type RedisTokenStore
- func (s *RedisTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
- func (s *RedisTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
- func (s *RedisTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
- func (s *RedisTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
- func (s *RedisTokenStore) GetToken(ctx context.Context, authenticationId string) (oauth2.TokenInfo, error)
- func (s *RedisTokenStore) RedisKey(name string, key string) string
- func (s *RedisTokenStore) RemoveByAccess(ctx context.Context, access string) error
- func (s *RedisTokenStore) RemoveByCode(ctx context.Context, code string) error
- func (s *RedisTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
- type RedisUserTokenCache
- func (u *RedisUserTokenCache) ClearUserTokens() bool
- func (u *RedisUserTokenCache) DelOverMaxOnlineCache() bool
- func (u *RedisUserTokenCache) ReleaseRedisConn()
- func (u *RedisUserTokenCache) SetToken(tokenExpire int64, token string) bool
- func (u *RedisUserTokenCache) SetUserTokensExpire(ts int64) bool
- func (u *RedisUserTokenCache) UserTokenExists(token string) (exists bool)
- type StoreTokenResolver
- type TokenRequest
- type UUIDTokenGenerator
Constants ¶
const ( ACCESS = "access:" AUTH_TO_ACCESS = "auth_to_access:" AUTH = "auth:" REFRESH_AUTH = "refresh_auth:" ACCESS_TO_REFRESH = "access_to_refresh:" REFRESH = "refresh:" REFRESH_TO_ACCESS = "refresh_to_access:" CLIENT_ID_TO_ACCESS = "client_id_to_access:" UNAME_TO_ACCESS = "uname_to_access:" )
Variables ¶
This section is empty.
Functions ¶
func AccessGenerate ¶
func AccessGenerate() oauth2.AccessGenerate
func DelTokenCacheFromRedis ¶
func DelTokenCacheFromRedis(userId int64)
DelTokenCacheFromRedis 用户密码修改后,删除redis所有的token
func InitTokenGenerator ¶
func InitTokenGenerator() oauth2.AccessGenerate
func InitTokenStore ¶
func InitTokenStore() oauth2.TokenStore
func NewDatabaseTokenStore ¶
func NewDatabaseTokenStore() (oauth2.TokenStore, error)
func NewFileTokenStore ¶
func NewJWTAccessGenerate ¶
func NewJWTAccessGenerate() oauth2.AccessGenerate
func NewMemeoryTokenStore ¶
func NewMemeoryTokenStore() (oauth2.TokenStore, error)
func NewRedisTokenStore ¶
func NewRedisTokenStore() (oauth2.TokenStore, error)
func NewUUIDAccessGenerate ¶
func NewUUIDAccessGenerate() oauth2.AccessGenerate
*
- UUID Token Generator
func ParseToken ¶
func TokenStore ¶
func TokenStore() oauth2.TokenStore
func ValidTokenCacheToRedis ¶
func ValidTokenCacheToRedis(userId int64)
本文件专门处理 token 缓存到 redis 的相关逻辑
Types ¶
type Authentication ¶
type Authentication struct { UserId string `json:"user_id"` Request TokenRequest `json:"request"` Authenticated bool `json:"authenticated"` }
func ParseAuthentication ¶
func ParseAuthentication(authenticationString string) (*Authentication, error)
func (*Authentication) GetId ¶
func (a *Authentication) GetId() string
type DatabaseTokenStore ¶
type DatabaseTokenStore struct { }
func (*DatabaseTokenStore) Create ¶
func (s *DatabaseTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
create and store the new token information
func (*DatabaseTokenStore) GetByAccess ¶
func (s *DatabaseTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
use the access token for token information data
func (*DatabaseTokenStore) GetByCode ¶
func (s *DatabaseTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
use the authorization code for token information data
func (*DatabaseTokenStore) GetByRefresh ¶
func (s *DatabaseTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
use the refresh token for token information data
func (*DatabaseTokenStore) GetToken ¶
func (s *DatabaseTokenStore) GetToken(ctx context.Context, key string) (oauth2.TokenInfo, error)
func (*DatabaseTokenStore) RemoveByAccess ¶
func (s *DatabaseTokenStore) RemoveByAccess(ctx context.Context, access string) error
use the access token to delete the token information
func (*DatabaseTokenStore) RemoveByCode ¶
func (s *DatabaseTokenStore) RemoveByCode(ctx context.Context, code string) error
delete the authorization code
func (*DatabaseTokenStore) RemoveByRefresh ¶
func (s *DatabaseTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
use the refresh token to delete the token information
type ITokenResolver ¶
func InitTokenResolver ¶
func InitTokenResolver() ITokenResolver
func TokenResolver ¶
func TokenResolver() ITokenResolver
type ITokenStore ¶
type JWTTokenResolver ¶
type JWTTokenResolver struct{}
func (*JWTTokenResolver) Resolve ¶
func (v *JWTTokenResolver) Resolve(ctx context.Context, tokenValue string) (oauth2.TokenInfo, error)
type StandardClaims struct { Audience string `json:"aud,omitempty"` ExpiresAt int64 `json:"exp,omitempty"` AccessCreateAt + AccessExpiresIn Id string `json:"jti,omitempty"` IssuedAt int64 `json:"iat,omitempty"` AccessCreateAt Issuer string `json:"iss,omitempty"` NotBefore int64 `json:"nbf,omitempty"` Subject string `json:"sub,omitempty"` UserId }
type OAuth2Token ¶
type RedisTokenStore ¶
type RedisTokenStore struct {
// contains filtered or unexported fields
}
func (*RedisTokenStore) Create ¶
func (s *RedisTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error
create and store the new token information
func (*RedisTokenStore) GetByAccess ¶
func (s *RedisTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)
use the access token for token information data
func (*RedisTokenStore) GetByCode ¶
func (s *RedisTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)
use the authorization code for token information data
func (*RedisTokenStore) GetByRefresh ¶
func (s *RedisTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
use the refresh token for token information data
func (*RedisTokenStore) GetToken ¶
func (s *RedisTokenStore) GetToken(ctx context.Context, authenticationId string) (oauth2.TokenInfo, error)
func (*RedisTokenStore) RedisKey ¶
func (s *RedisTokenStore) RedisKey(name string, key string) string
func (*RedisTokenStore) RemoveByAccess ¶
func (s *RedisTokenStore) RemoveByAccess(ctx context.Context, access string) error
use the access token to delete the token information
func (*RedisTokenStore) RemoveByCode ¶
func (s *RedisTokenStore) RemoveByCode(ctx context.Context, code string) error
delete the authorization code
func (*RedisTokenStore) RemoveByRefresh ¶
func (s *RedisTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error
use the refresh token to delete the token information
type RedisUserTokenCache ¶
type RedisUserTokenCache struct {
// contains filtered or unexported fields
}
保存用户的所有Token
func CreateRedisUserTokenStorage ¶
func CreateRedisUserTokenStorage(userId int64) *RedisUserTokenCache
func (*RedisUserTokenCache) ClearUserTokens ¶
func (u *RedisUserTokenCache) ClearUserTokens() bool
ClearUserToken 清除某个用户的全部缓存,当用户更改密码或者用户被禁用则删除该用户的全部缓存
func (*RedisUserTokenCache) DelOverMaxOnlineCache ¶
func (u *RedisUserTokenCache) DelOverMaxOnlineCache() bool
DelOverMaxOnlineCache 删除缓存,删除超过系统允许最大在线数量之外的用户
func (*RedisUserTokenCache) ReleaseRedisConn ¶
func (u *RedisUserTokenCache) ReleaseRedisConn()
ReleaseRedisConn 释放redis
func (*RedisUserTokenCache) SetToken ¶
func (u *RedisUserTokenCache) SetToken(tokenExpire int64, token string) bool
SetTokenCache 设置缓存
func (*RedisUserTokenCache) SetUserTokensExpire ¶
func (u *RedisUserTokenCache) SetUserTokensExpire(ts int64) bool
SetUserTokenExpire 设置用户的 usertoken 键过期时间 参数: 时间戳
func (*RedisUserTokenCache) UserTokenExists ¶
func (u *RedisUserTokenCache) UserTokenExists(token string) (exists bool)
TokenCacheIsExists 查询token是否在redis存在
type StoreTokenResolver ¶
type StoreTokenResolver struct {
TokenStore oauth2.TokenStore `inject:"tokenStore"`
}
type TokenRequest ¶
type UUIDTokenGenerator ¶
type UUIDTokenGenerator struct {
TokenStore ITokenStore `inject:"tokenStore"`
}