claims

package
v0.8.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIDClaimNotFound    = errors.New("id claim not found")
	ErrInvalidIDClaim     = errors.New("invalid id claim")
	ErrNilClaims          = errors.New("claims is nil")
	ErrNilTokenValidator  = errors.New("nil token validator")
	ErrNilClaimsValidator = errors.New("nil claims validator")
)

Functions

func GetToken added in v0.7.0

func GetToken(token gojwttoken.Token, id int64, logger *slog.Logger)

GetToken logs the get token

Parameters:

  • token: The token being retrieved
  • id: The ID associated with the token
  • logger: The logger to use for logging (optional, can be nil)

func GetTokenFailed added in v0.7.0

func GetTokenFailed(err error, logger *slog.Logger)

GetTokenFailed logs the get token failure

Parameters:

  • err: The error that occurred while retrieving the token
  • logger: The logger to use for logging (optional, can be nil)

func RevokeToken added in v0.7.0

func RevokeToken(
	token gojwttoken.Token,
	id int64,
	logger *slog.Logger,
)

RevokeToken logs the revoke token

Parameters:

  • token: The token being revoked
  • id: The ID associated with the token
  • logger: The logger to use for logging (optional, can be nil)

func RevokeTokenFailed added in v0.7.0

func RevokeTokenFailed(err error, logger *slog.Logger)

RevokeTokenFailed logs the revoke token failure

Parameters:

  • err: The error that occurred while revoking the token
  • logger: The logger to use for logging (optional, can be nil)

func SetToken added in v0.7.0

func SetToken(token gojwttoken.Token, id int64, logger *slog.Logger)

SetToken logs the set token

Parameters:

  • token: The token being set
  • id: The ID associated with the token
  • logger: The logger to use for logging (optional, can be nil)

func SetTokenFailed added in v0.7.0

func SetTokenFailed(err error, logger *slog.Logger)

SetTokenFailed logs the set token failure

Parameters:

  • err: The error that occurred while setting the token
  • logger: The logger to use for logging (optional, can be nil)

Types

type ClaimsValidator added in v0.7.0

type ClaimsValidator interface {
	ValidateClaims(
		ctx context.Context,
		claims jwt.MapClaims,
		token gojwttoken.Token,
	) (bool, error)
}

ClaimsValidator interface

type DefaultClaimsValidator added in v0.7.0

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

DefaultClaimsValidator is the default implementation of the ClaimsValidator interface

func NewDefaultClaimsValidator added in v0.7.0

func NewDefaultClaimsValidator(
	tokenValidator TokenValidator,
) (*DefaultClaimsValidator, error)

NewDefaultClaimsValidator creates a new default claims validator

Parameters:

  • tokenValidator: the token validator

Returns:

  • *DefaultValidator: the default validator
  • error: if there was an error creating the default validator

func (DefaultClaimsValidator) ValidateClaims added in v0.7.0

func (d DefaultClaimsValidator) ValidateClaims(
	ctx context.Context,
	claims jwt.MapClaims,
	token gojwttoken.Token,
) (bool, error)

ValidateClaims validates the claims

Parameters:

  • ctx: the context
  • claims: the claims to validate
  • token: the token type (access or refresh)

Returns:

  • bool: true if the claims are valid, false otherwise
  • error: if there was an error validating the claims

type TokenValidator added in v0.7.0

type TokenValidator interface {
	AddRefreshToken(
		ctx context.Context,
		id string,
		expiresAt time.Time,
	) error
	AddAccessToken(
		ctx context.Context,
		id string,
		parentRefreshTokenID string,
		expiresAt time.Time,
	) error
	RevokeToken(ctx context.Context, token gojwttoken.Token, id string) error
	IsTokenValid(ctx context.Context, token gojwttoken.Token, id string) (bool, error)
}

TokenValidator interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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