token

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultExpiration = time.Hour * 8
	MaxExpiration     = 365 * 24 * time.Hour
)
View Source
var (
	ErrTokenNotFound = redis.Nil
)

Functions

func ContextWithToken

func ContextWithToken(ctx context.Context, token *apiv2.Token) context.Context

ContextWithToken stores the token in the Context Can later retrieved with TokenFromContext

func NewJWT

func NewJWT(tokenType apiv2.TokenType, subject, issuer string, expires time.Duration, secret crypto.PrivateKey) (string, *apiv2.Token, error)

func TokenFromContext

func TokenFromContext(ctx context.Context) (*apiv2.Token, bool)

TokenFromContext retrieves the token and ok from the context if previously stored by calling ContextWithToken.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims

	Type string `json:"type"`
}

func ParseJWTToken

func ParseJWTToken(token string) (*Claims, error)

ParseJWTToken unverified to Claims to get Issuer,Subject, Roles and Permissions

func Validate added in v0.1.1

func Validate(ctx context.Context, log *slog.Logger, tokenString string, set jwk.Set, allowedIssuers []string) (*Claims, error)

type TokenStore

type TokenStore interface {
	Set(ctx context.Context, token *apiv2.Token) error
	Get(ctx context.Context, userid, tokenid string) (*apiv2.Token, error)
	List(ctx context.Context, userid string) ([]*apiv2.Token, error)
	AdminList(ctx context.Context) ([]*apiv2.Token, error)
	Revoke(ctx context.Context, userid, tokenid string) error
	Migrate(ctx context.Context, log *slog.Logger) error
}

func NewRedisStore

func NewRedisStore(client *redis.Client) TokenStore

Jump to

Keyboard shortcuts

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