jwt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixBlacklist = "bl_"
)

Variables

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

Functions

This section is empty.

Types

type AuthStore

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

AuthStore handles persistence for authentication tokens.

func NewAuthStore

func NewAuthStore(database *gorm.DB, signingKey string, expiration time.Duration) *AuthStore

func (*AuthStore) Blacklist

func (s *AuthStore) Blacklist(ctx context.Context, jti string, expiresAt time.Time) error

func (*AuthStore) DeleteExpiredTokens

func (s *AuthStore) DeleteExpiredTokens(ctx context.Context, now time.Time) error

func (*AuthStore) GenerateToken

func (s *AuthStore) GenerateToken(actor mdk.Actor) (string, error)

GenerateToken creates a new JWT for an actor.

func (*AuthStore) GetRefreshToken

func (s *AuthStore) GetRefreshToken(ctx context.Context, token string) (*RefreshToken, error)

func (*AuthStore) IsBlacklisted

func (s *AuthStore) IsBlacklisted(ctx context.Context, jti string) (bool, error)

func (*AuthStore) RevokeRefreshToken

func (s *AuthStore) RevokeRefreshToken(ctx context.Context, token string) error

func (*AuthStore) SaveRefreshToken

func (s *AuthStore) SaveRefreshToken(ctx context.Context, t *RefreshToken) error

func (*AuthStore) ValidateToken

func (s *AuthStore) ValidateToken(ctx context.Context, tokenString string) (mdk.Actor, error)

ValidateToken parses and validates a JWT string.

type Blacklist

type Blacklist struct {
	ID        string    `gorm:"primaryKey"`
	JTI       string    `gorm:"uniqueIndex;not null"`
	ExpiresAt time.Time `gorm:"index;not null"`
}

Blacklist tracks revoked JWT IDs.

type Claims

type Claims struct {
	ActorID   string        `json:"actor_id"`
	ActorType mdk.ActorType `json:"actor_type"`
	jwt.RegisteredClaims
}

Claims represents the JWT actor payload claims.

type RefreshToken

type RefreshToken struct {
	ID        string    `gorm:"primaryKey"`
	ActorID   string    `gorm:"index;not null"`
	Token     string    `gorm:"uniqueIndex;not null"`
	ExpiresAt time.Time `gorm:"not null"`
	RevokedAt *time.Time
	CreatedAt time.Time
}

RefreshToken represents a long-lived token used to generate new JWTs.

Jump to

Keyboard shortcuts

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