redis

package
v0.7.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ParentRefreshTokenIDPrefix is the prefix of the Parent Refresh Token ID key
	ParentRefreshTokenIDPrefix = "prt"

	// KeySeparator is the separator for the Redis keys
	KeySeparator = gostringsseparator.Dots
)

Functions

This section is empty.

Types

type TokenValidator

type TokenValidator struct {
	// contains filtered or unexported fields
}

TokenValidator struct

func NewTokenValidator

func NewTokenValidator(
	redisClient *redis.Client,
	logger *slog.Logger,
) (
	*TokenValidator,
	error,
)

NewTokenValidator creates a new token validator

Parameters:

  • redisClient: The Redis client
  • logger: The logger (optional, can be nil)

Returns:

  • *TokenValidator: The token validator
  • error: An error if the Redis client is nil

func (*TokenValidator) AddAccessToken

func (t *TokenValidator) AddAccessToken(
	ctx context.Context,
	id string,
	parentRefreshTokenID string,
	expiresAt time.Time,
) error

AddAccessToken adds an access token

Parameters:

  • ctx: The context
  • 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 adding the access token fails

func (*TokenValidator) AddRefreshToken

func (t *TokenValidator) AddRefreshToken(
	ctx context.Context,
	id string,
	expiresAt time.Time,
) error

AddRefreshToken adds a refresh token

Parameters:

  • 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 adding the refresh token fails

func (*TokenValidator) GetKey

func (t *TokenValidator) 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 token
  • error: An error if the token abbreviation fails

func (*TokenValidator) GetParentRefreshTokenKey

func (t *TokenValidator) GetParentRefreshTokenKey(
	id string,
) (string, error)

GetParentRefreshTokenKey gets the parent refresh token key

Parameters:

  • id: The ID associated with the token

Returns:

  • string: The key for the parent refresh token
  • error: An error if the token validator is nil

func (*TokenValidator) IsTokenValid

func (t *TokenValidator) IsTokenValid(
	ctx context.Context,
	token gojwttoken.Token,
	id string,
) (bool, error)

IsTokenValid checks if the token is valid

Parameters:

  • ctx: The context
  • 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 is nil or if checking the token fails

func (*TokenValidator) RevokeToken

func (t *TokenValidator) RevokeToken(
	ctx context.Context,
	token gojwttoken.Token,
	id string,
) error

RevokeToken revokes the token

Parameters:

  • ctx: The context
  • 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 fails

Jump to

Keyboard shortcuts

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