cache

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

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"
)
View Source
var (
	ErrParentRefreshTokenNotFound    = errors.New("parent refresh token not found")
	ErrInvalidParentRefreshTokenItem = errors.New("invalid parent refresh token item")
	ErrInvalidTokenItem              = errors.New("invalid token item")
)

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

Jump to

Keyboard shortcuts

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