Documentation
¶
Index ¶
- Variables
- type TokenValidator
- func (t *TokenValidator) AddAccessToken(ctx context.Context, id string, parentRefreshTokenID string, ...) error
- func (t *TokenValidator) AddRefreshToken(ctx context.Context, id string, expiresAt time.Time) error
- func (t *TokenValidator) GetParentRefreshTokenKey(id string) (string, error)
- func (t *TokenValidator) GetTokenKey(token gojwttoken.Token, id string) (string, error)
- func (t *TokenValidator) IsTokenValid(ctx context.Context, token gojwttoken.Token, id string) (bool, error)
- func (t *TokenValidator) RevokeToken(ctx context.Context, token gojwttoken.Token, id string) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // KeySeparator is the separator for the cache keys KeySeparator = gostringsseparator.Dots // ParentRefreshTokenIDPrefix is the prefix of the Parent Refresh Token ID key ParentRefreshTokenIDPrefix = "PRT" )
Functions ¶
This section is empty.
Types ¶
type TokenValidator ¶
type TokenValidator struct {
// contains filtered or unexported fields
}
TokenValidator struct
func NewTokenValidator ¶
func NewTokenValidator(logger *slog.Logger) *TokenValidator
NewTokenValidator creates a new token validator
Parameters:
- logger: The logger (optional, can be nil)
Returns:
- *TokenValidator: The token validator
func (*TokenValidator) AddAccessToken ¶
func (t *TokenValidator) AddAccessToken( ctx context.Context, id string, parentRefreshTokenID string, expiresAt time.Time, ) error
AddAccessToken sets a token in the cache
Parameters:
- ctx: The context (not used, but kept for interface consistency)
- id: The ID associated with the token
- parentRefreshTokenID: The parent refresh token ID
- expiresAt: The expiration time of the token
Returns:
- error: An error if the token validator is nil or if setting the token in the cache fails
func (*TokenValidator) AddRefreshToken ¶
func (t *TokenValidator) AddRefreshToken( ctx context.Context, id string, expiresAt time.Time, ) error
AddRefreshToken sets a token in the cache
Parameters:
- ctx: The context (not used, but kept for interface consistency)
- token: The token
- id: The ID associated with the token
- expiresAt: The expiration time of the token
Returns:
- error: An error if the token validator is nil or if setting the token in the cache fails
func (*TokenValidator) GetParentRefreshTokenKey ¶
func (t *TokenValidator) GetParentRefreshTokenKey( id string, ) (string, error)
GetParentRefreshTokenKey gets the parent
Parameters:
- id: The ID of the refresh token
- parentTokenPrefix: The parent token prefix
Returns:
- string: The key for the cache
- error: An error if the token validator is nil
func (*TokenValidator) GetTokenKey ¶
func (t *TokenValidator) GetTokenKey( token gojwttoken.Token, id string, ) (string, error)
GetTokenKey gets the JWT Identifier key
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- string: The key for the cache
- error: An error if the token validator is nil or if the token abbreviation fails
func (*TokenValidator) IsTokenValid ¶
func (t *TokenValidator) IsTokenValid( ctx context.Context, token gojwttoken.Token, id string, ) (bool, error)
IsTokenValid checks if a token is valid in the cache
Parameters:
- ctx: The context (not used, but kept for interface consistency)
- token: The token
- id: The ID associated with the token
Returns:
- bool: Whether the token is valid
- error: An error if the token validator is nil or if checking the token in the cache fails
func (*TokenValidator) RevokeToken ¶
func (t *TokenValidator) RevokeToken( ctx context.Context, token gojwttoken.Token, id string, ) error
RevokeToken revokes a token in the cache
Parameters:
- ctx: The context (not used, but kept for interface consistency)
- token: The token
- id: The ID associated with the token
Returns:
- error: An error if the token validator is nil or if revoking the token in the cache fails
Click to show internal directories.
Click to hide internal directories.