session

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package session provides JWT-based session ID generation and validation

Index

Constants

View Source
const (
	// DefaultSessionDuration is the default duration for session JWTs
	DefaultSessionDuration = 24 * time.Hour
)

Variables

This section is empty.

Functions

func WithRedisClient added in v0.6.0

func WithRedisClient(client *redis.Client) func(c *Cache)

WithRedisClient configures the cache to use an existing redis client

Types

type Cache

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

Cache implements a cache

func NewCache

func NewCache(opts ...func(*Cache)) (*Cache, error)

NewCache returns a new cache. Pass WithRedisClient to use an external redis store; otherwise an in-memory cache is returned.

func (*Cache) AddSession

func (c *Cache) AddSession(ctx context.Context, key, mcpServerID, mcpSession string) (bool, error)

AddSession will add a session under the key. If the key exists it will append that session

func (*Cache) DeleteSessions

func (c *Cache) DeleteSessions(ctx context.Context, key ...string) error

DeleteSessions deletes sessions and associated metadata from the cache

func (*Cache) GetClientElicitation added in v0.6.0

func (c *Cache) GetClientElicitation(ctx context.Context, gatewaySessionID string) (bool, error)

GetClientElicitation returns whether the client for this gateway session supports elicitation

func (*Cache) GetSession

func (c *Cache) GetSession(ctx context.Context, key string) (map[string]string, error)

GetSession returns a session from the cache

func (*Cache) KeyExists

func (c *Cache) KeyExists(ctx context.Context, key string) (bool, error)

KeyExists checks if a key exists in the cache

func (*Cache) RemoveServerSession

func (c *Cache) RemoveServerSession(ctx context.Context, key, mcpServerID string) error

RemoveServerSession remove specific server session form cache

func (*Cache) SetClientElicitation added in v0.6.0

func (c *Cache) SetClientElicitation(ctx context.Context, gatewaySessionID string) error

SetClientElicitation records that the client for this gateway session supports elicitation

type Claims

type Claims struct {
	jwt.RegisteredClaims
}

Claims represents the claims in a session JWT

type Deleter

type Deleter interface {
	DeleteSessions(ctx context.Context, key ...string) error
}

Deleter interface for providing session deletion

type JWTManager

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

JWTManager handles JWT generation and validation for session IDs

func NewJWTManager

func NewJWTManager(signingKey string, sessionLength int64, logger *slog.Logger, sessionHandler Deleter) (*JWTManager, error)

NewJWTManager creates a new JWT manager with the provided signing key

func (*JWTManager) Generate

func (m *JWTManager) Generate() string

Generate returns a session id JWT to fullfil SessionIdManager interface

func (*JWTManager) GetExpiresIn

func (m *JWTManager) GetExpiresIn(tokenValue string) (time.Time, error)

GetExpiresIn returns the time a token will expire

func (*JWTManager) Terminate

func (m *JWTManager) Terminate(sessionID string) (isNotAllowed bool, err error)

Terminate part of the SessionIDManager interface. Will remove the associated sessions from cache

func (*JWTManager) Validate

func (m *JWTManager) Validate(tokenValue string) (bool, error)

Validate validates a JWT token and fulfils SessionIdManager interface. returns IsInValid as a bool

Jump to

Keyboard shortcuts

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