Documentation
¶
Index ¶
- Constants
- Variables
- type TokenValidatorService
- func (d *TokenValidatorService) GetKey(token gojwttoken.Token, id string) (string, error)
- func (d *TokenValidatorService) IsValid(token gojwttoken.Token, id string) (bool, error)
- func (d *TokenValidatorService) Revoke(token gojwttoken.Token, id string) error
- func (d *TokenValidatorService) Set(token gojwttoken.Token, id string, isValid bool, expiresAt time.Time) error
Constants ¶
View Source
const (
ErrFailedToParseBoolValue = "failed to parse bool value: %v"
)
Variables ¶
View Source
var ( // JwtIdentifierPrefix is the prefix of the JWT Identifier key JwtIdentifierPrefix = "jti" // JwtIdentifierSeparator is the separator of the JWT identifier prefixes JwtIdentifierSeparator = gostringsseparator.Dots )
Functions ¶
This section is empty.
Types ¶
type TokenValidatorService ¶
type TokenValidatorService struct {
// contains filtered or unexported fields
}
TokenValidatorService struct
func NewTokenValidatorService ¶
func NewTokenValidatorService( redisClient *redis.Client, logger *slog.Logger, ) ( *TokenValidatorService, error, )
NewTokenValidatorService creates a new token validator service
Parameters:
- redisClient: The Redis client
- logger: The logger (optional, can be nil)
Returns:
- *TokenValidatorService: The token validator service
- error: An error if the Redis client is nil
func (*TokenValidatorService) GetKey ¶
func (d *TokenValidatorService) GetKey( token gojwttoken.Token, id string, ) (string, error)
GetKey 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 abbreviation fails
func (*TokenValidatorService) IsValid ¶ added in v0.4.7
func (d *TokenValidatorService) IsValid( token gojwttoken.Token, id string, ) (bool, error)
IsValid checks if the token is valid
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- bool: True if the token is valid, false if revoked
- error: An error if the token validator service is nil or if checking the token in the cache fails
func (*TokenValidatorService) Revoke ¶ added in v0.4.7
func (d *TokenValidatorService) Revoke( token gojwttoken.Token, id string, ) error
Revoke revokes the token
Parameters:
- token: The token
- id: The ID associated with the token
Returns:
- error: An error if the token validator service is nil or if revoking the token in the cache fails
func (*TokenValidatorService) Set ¶
func (d *TokenValidatorService) Set( token gojwttoken.Token, id string, isValid bool, expiresAt time.Time, ) error
Set sets the token with the value and expiration
Parameters:
- token: The token
- id: The ID associated with the token
- isValid: The value to set (true if valid, false if revoked)
- expiresAt: The expiration time of the token
Returns:
- error: An error if the token validator service is nil or if setting the token in the cache fails
Click to show internal directories.
Click to hide internal directories.