authen

package
v0.0.0-...-3839eb7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func GetContextKeyInfo(ctx *gin.Context) entity.APIKey

GetContextKeyInfo returns the key info in current request

func SetContextAPIInfo

func SetContextAPIInfo(ctx *gin.Context, key entity.APIKey)

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

func (a APIKeyCacheAuthor) Authenticate(ctx context.Context, key, obj, act string) (entity.APIKey, error)

func (APIKeyCacheAuthor) Issue

func (a APIKeyCacheAuthor) Issue(ctx context.Context, userId string, name string, exp int64, perms []uint) (entity.APIKey, error)

type Jwt

type Jwt struct {
	Tk      jwtx.Jwt
	Payload UserClaims
}

type KeyAuthor

type KeyAuthor interface {
	Authenticate(ctx context.Context, key, obj, act string) (entity.APIKey, error)
}

type KeyIssuer

type KeyIssuer interface {
	Issue(ctx context.Context, userId string, name string, exp int64, perms []uint) (entity.APIKey, error)
}

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)

func (RefreshTokenAuthor) Parse

func (r RefreshTokenAuthor) Parse(ctx context.Context, token string) (Token, error)

func (RefreshTokenAuthor) Refresh

func (r RefreshTokenAuthor) Refresh(ctx context.Context, accessToken string, refreshToken string) (Token, error)

type Token

type Token struct {
	Access  Jwt
	Refresh Jwt
}

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

type TokenParser interface {
	Parse(ctx context.Context, token string) (Token, error)
}

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

Jump to

Keyboard shortcuts

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