v12.2.10 Latest Latest

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

Go to latest
Published: Jan 18, 2024 License: BSD-3-Clause Imports: 6 Imported by: 1




This section is empty.


This section is empty.


This section is empty.


type Blocklist

type Blocklist struct {
	// GetKey is a function which can be used how to extract
	// the unique identifier for a token.
	// Required. By default the token key is extracted through the claims.ID ("jti").
	GetKey func(token []byte, claims jwt.Claims) string
	// Prefix the token key into the redis database.
	// Note that if you can also select a different database
	// through ClientOptions (or ClusterOptions).
	// Defaults to empty string (no prefix).
	Prefix string

	// Customize any go-redis fields manually
	// before Connect.
	ClientOptions  Options
	ClusterOptions ClusterOptions
	// contains filtered or unexported fields

Blocklist is a jwt.Blocklist backed by Redis.

func NewBlocklist

func NewBlocklist() *Blocklist

NewBlocklist returns a new redis-based Blocklist. Modify its ClientOptions or ClusterOptions depending the application needs and call its Connect.


blocklist := NewBlocklist()
blocklist.ClientOptions.Addr = ...
err := blocklist.Connect()

And register it:

verifier := jwt.NewVerifier(...)
verifier.Blocklist = blocklist

func (*Blocklist) Connect

func (b *Blocklist) Connect() error

Connect prepares the redis client and fires a ping response to it.

func (*Blocklist) Count

func (b *Blocklist) Count() (int64, error)

Count returns the total amount of tokens stored.

func (*Blocklist) Del

func (b *Blocklist) Del(key string) error

Del removes a token from the storage.

func (*Blocklist) Has

func (b *Blocklist) Has(key string) (bool, error)

Has reports whether a specific token exists in the storage.

func (*Blocklist) InvalidateToken

func (b *Blocklist) InvalidateToken(token []byte, c jwt.Claims) error

InvalidateToken invalidates a verified JWT token.

func (*Blocklist) IsConnected

func (b *Blocklist) IsConnected() bool

IsConnected reports whether the Connect function was called.

func (*Blocklist) ValidateToken

func (b *Blocklist) ValidateToken(token []byte, c jwt.Claims, err error) error

ValidateToken checks if the token exists and

type Client

type Client interface {
	redis.Cmdable // Commands.
	io.Closer     // CloseConnection.

Client is the interface which both go-redis Client and Cluster Client implements.

type ClusterOptions

type ClusterOptions = redis.ClusterOptions

ClusterOptions is just a type alias for the go-redis Cluster Client Options.

type Options

type Options = redis.Options

Options is just a type alias for the go-redis Client Options.

Jump to

Keyboard shortcuts

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