Skip to content

internal/token

github.com/gamidoc/backend/internal/token

Types

Blacklist

type Blacklist struct {

Claims

type Claims struct {

Manager

type Manager struct {

RefreshStore

type RefreshStore struct {

Functions

Blacklist.Add

func (bl *Blacklist) Add(ctx context.Context, jti string, expiresAt time.Time) error {

Add blacklists a JWT ID until its natural expiry time.

Blacklist.IsBlacklisted

func (bl *Blacklist) IsBlacklisted(ctx context.Context, jti string) (bool, error) {

IsBlacklisted returns true if the jti has been revoked.

Manager.ExpiresIn

func (m *Manager) ExpiresIn() time.Duration {

Manager.Generate

func (m *Manager) Generate(userID string) (string, error) {

Manager.Parse

func (m *Manager) Parse(tokenString string) (Claims, error) {

NewBlacklist

func NewBlacklist(redis *goredis.Client) *Blacklist {

NewManager

func NewManager(secret string, expiresIn time.Duration) *Manager {

NewRefreshStore

func NewRefreshStore(redis *goredis.Client, ttl time.Duration) *RefreshStore {

RefreshStore.GenerateAndStore

func (s *RefreshStore) GenerateAndStore(ctx context.Context, userID string) (string, error) {

GenerateAndStore creates a new opaque refresh token, stores it in Redis keyed to the userID, and returns the token string.

RefreshStore.Revoke

func (s *RefreshStore) Revoke(ctx context.Context, tokenStr string) error {

Revoke deletes a refresh token from Redis.

RefreshStore.TTL

func (s *RefreshStore) TTL() time.Duration {

RefreshStore.Validate

func (s *RefreshStore) Validate(ctx context.Context, tokenStr string) (string, error) {

Validate looks up the refresh token and returns the associated userID.

Variables

ErrInvalidToken

var ErrInvalidToken = errors.New("invalid token")