Documentation
¶
Index ¶
- Variables
- func GetContextKeyInfo(ctx *gin.Context) entity.APIKey
- func SetContextAPIInfo(ctx *gin.Context, key entity.APIKey)
- func SetContextTokenInfo(ctx *gin.Context, claims UserClaims)
- type APIKeyCacheAuthor
- type Jwt
- type KeyAuthor
- type KeyIssuer
- type RefreshTokenAuthor
- type Token
- type TokenIssuer
- type TokenParser
- type TokenRefresher
- type UserClaims
- type UserPayload
Constants ¶
This section is empty.
Variables ¶
var ( ErrTokenExpired = errors.New("access token expired") ErrTokenNeedRefreshed = errors.New("token need to be refreshed") ErrInvalidTokenPayload = errors.New("invalid token payload") ErrInvalidToken = errors.New("invalid token") ErrTokenMisMatch = errors.New("token mismatch") ErrTokenExpirationExceed = errors.New("token expiration exceeded") )
Functions ¶
func GetContextKeyInfo ¶
GetContextKeyInfo returns the key info in current request
func SetContextTokenInfo ¶
func SetContextTokenInfo(ctx *gin.Context, claims UserClaims)
Types ¶
type APIKeyCacheAuthor ¶
type APIKeyCacheAuthor struct {
// contains filtered or unexported fields
}
func NewAPIKeyCacheAuthor ¶
func NewAPIKeyCacheAuthor(ds *data.DataSource, resolver role.Resolver, cache cache.KeyCache) APIKeyCacheAuthor
func (APIKeyCacheAuthor) Authenticate ¶
type Jwt ¶
type Jwt struct { Tk jwtx.Jwt Payload UserClaims }
type RefreshTokenAuthor ¶
type RefreshTokenAuthor struct {
// contains filtered or unexported fields
}
func NewRefreshTokenAuthor ¶
func NewRefreshTokenAuthor(cfg *conf.JwtConf, accessCache cache.TokenCache, refreshCache cache.TokenCache) RefreshTokenAuthor
func (RefreshTokenAuthor) Issue ¶
func (r RefreshTokenAuthor) Issue(ctx context.Context, payload UserPayload) (Token, error)
type TokenIssuer ¶
type TokenIssuer interface {
Issue(ctx context.Context, payload UserPayload) (Token, error)
}
TokenIssuer The TokenIssuer should issue a new jwt token and return the token info
type TokenParser ¶
TokenParser The TokenParser should verify if the request has been authenticated.
type TokenRefresher ¶
type TokenRefresher interface {
Refresh(ctx context.Context, accessToken string, refreshToken string) (Token, error)
}
TokenRefresher if refresh-token expired , TokenRefresher will not refresh token else if access-token has expired after delay duration, TokenRefresher will not refresh token else if access-token has expired before delay duration, TokenRefresher will issue a new access-token else if access-token has not expired, TokenRefresher will renewal the access-token expired time
type UserClaims ¶
type UserClaims struct { UserPayload jwt.RegisteredClaims }
func GetContextTokenInfo ¶
func GetContextTokenInfo(ctx *gin.Context) UserClaims
GetContextTokenInfo returns the token info in current request
type UserPayload ¶
type UserPayload struct { Username string `json:"username"` UUID string `json:"uuid"` Persistent bool `json:"persistent"` }
UserPayload basic user info