session

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package session owns browser session data, expiry, revocation and encrypted shared persistence. It has no process configuration or authentication client.

Index

Constants

View Source
const CookieName = "mcp_ui_session"
View Source
const Duration = 8 * time.Hour

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Put stores a session until its ExpiresAt. It may also drop expired rows.
	Put(ctx context.Context, sess Session, now time.Time) error
	// Get returns a live session. A missing or expired session is (_, false, nil).
	Get(ctx context.Context, id string, now time.Time) (Session, bool, error)
	Delete(ctx context.Context, id string) error
}

Backend persists UI sessions. The default in-memory backend keeps the single-replica behavior (sessions are lost on restart); a shared backend lets several UI replicas validate the same session cookie.

func NewBackend

func NewBackend(ctx context.Context, kind, dsn, key string) (Backend, error)

NewBackend selects a backend from UI_SESSION_STORE (memory|postgres; default memory).

type Principal

type Principal struct {
	Role     string `json:"role,omitempty"`
	Subject  string `json:"subject,omitempty"`
	Email    string `json:"email,omitempty"`
	AuthType string `json:"auth_type,omitempty"`
}

type Session

type Session struct {
	ID                 string
	ExpiresAt          time.Time
	Principal          Principal
	UpstreamAuthHeader string
	UpstreamAPIKey     string
	// CSRFToken is the session-bound synchroniser token. It is handed to
	// same-origin JavaScript and required back on every state-changing
	// request; the browser handler owns validation in the UI's csrf.go.
	CSRFToken string
}

type Store

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

Store issues, looks up and revokes UI sessions on top of a backend.

func NewStore

func NewStore(now func() time.Time) *Store

func NewStoreWithBackend

func NewStoreWithBackend(backend Backend, now func() time.Time) *Store

func (*Store) Create

func (s *Store) Create(ctx context.Context, session Session) (Session, error)

func (*Store) Delete

func (s *Store) Delete(id string)

func (*Store) FromRequest

func (s *Store) FromRequest(r *http.Request) (Session, bool)

func (*Store) Get

func (s *Store) Get(id string) (Session, bool)

func (*Store) GetContext

func (s *Store) GetContext(ctx context.Context, id string) (Session, bool)

GetContext fails closed: a backend error is treated as "no session".

Jump to

Keyboard shortcuts

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