Documentation
¶
Overview ¶
Package store persists the bridge state in SQLite, with secrets encrypted by AES-GCM.
Index ¶
- Constants
- Variables
- func MasterKey(dir string, useKeyring bool) (key []byte, source string, err error)
- func RandomToken(prefix string) string
- type Account
- type Client
- type Grant
- type Host
- type Store
- func (s *Store) Account(ctx context.Context, userID, accountID string) (*Account, error)
- func (s *Store) Accounts(ctx context.Context, userID string) ([]*Account, error)
- func (s *Store) AuthRequest(ctx context.Context, id string, v any, consume bool) error
- func (s *Store) Client(ctx context.Context, id string) (*Client, error)
- func (s *Store) Close() error
- func (s *Store) ConsumeCode(ctx context.Context, code string) (*Grant, error)
- func (s *Store) Hash(secret string) string
- func (s *Store) Host(ctx context.Context, issuer, kind string) (*Host, error)
- func (s *Store) Key(purpose string) []byte
- func (s *Store) Purge(ctx context.Context) error
- func (s *Store) RevokeToken(ctx context.Context, token, clientID string) error
- func (s *Store) RotateRefresh(ctx context.Context, token, clientID string) (*Grant, error)
- func (s *Store) SaveAccount(ctx context.Context, a *Account) (string, error)
- func (s *Store) SaveAuthRequest(ctx context.Context, id string, v any, ttl time.Duration) error
- func (s *Store) SaveClient(ctx context.Context, c *Client) error
- func (s *Store) SaveCode(ctx context.Context, code string, g *Grant, ttl time.Duration) error
- func (s *Store) SaveHost(ctx context.Context, issuer, kind string, h *Host) error
- func (s *Store) SaveToken(ctx context.Context, token, kind string, g *Grant, ttl time.Duration) error
- func (s *Store) Seal(aad string, v any) ([]byte, error)
- func (s *Store) SetDefault(ctx context.Context, userID, email string) error
- func (s *Store) StaticHosts(ctx context.Context, kind string) ([]string, error)
- func (s *Store) Token(ctx context.Context, token, kind string) (*Grant, error)
- func (s *Store) Unseal(aad string, data []byte, v any) error
- func (s *Store) UpdateToken(ctx context.Context, accountID string, t *oauth2.Token) error
- func (s *Store) UpsertUser(ctx context.Context, issuer, subject string) (string, error)
- func (s *Store) UserExists(ctx context.Context, id string) bool
Constants ¶
const ( AccessToken = "access" RefreshToken = "refresh" )
Token kinds.
const LocalUser = "local"
LocalUser is the single user of the stdio mode.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a record does not exist or has expired.
var ErrTokenReuse = errors.New("refresh token reuse")
ErrTokenReuse means a rotated refresh token was presented again; its whole family is revoked.
Functions ¶
func MasterKey ¶
MasterKey loads the master key of dir or generates it on first start. With useKeyring, a key is kept in the OS keyring when one is available; otherwise, or when a key file already exists, it lives in dir/master.key (mode 0600).
func RandomToken ¶
RandomToken returns a URL-safe random string with prefix.
Types ¶
type Account ¶
type Account struct {
ID string
UserID string
Email string
Issuer string
SessionURL string
Token *oauth2.Token
Default bool
}
Account is a connected mail account with its mail-server token.
type Client ¶
type Client struct {
ClientID string `json:"client_id"`
ClientName string `json:"client_name,omitempty"`
RedirectURIs []string `json:"redirect_uris"`
AuthMethod string `json:"token_endpoint_auth_method"`
SecretHash string `json:"-"`
}
Client is an MCP client registered at the bridge (RFC 7591).
type Grant ¶
type Grant struct {
UserID string `json:"user_id"`
ClientID string `json:"client_id"`
RedirectURI string `json:"redirect_uri,omitempty"`
CodeChallenge string `json:"code_challenge,omitempty"`
Resource string `json:"resource"`
Scope string `json:"scope"`
ExpiresAt int64 `json:"-"`
Family string `json:"-"`
}
Grant is what an authorization code or token stands for.
type Host ¶
type Host struct {
Meta *mailauth.Meta
Registration *mailauth.Registration
}
Host is a discovered authorization server and this bridge's registration there.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the bridge database.
func (*Store) Accounts ¶
Accounts lists the accounts of a user. Accounts whose token cannot be decrypted are skipped.
func (*Store) AuthRequest ¶
AuthRequest loads a pending authorization request; with consume it is deleted.
func (*Store) ConsumeCode ¶
ConsumeCode redeems an authorization code once. The code is kept until it expires: presenting it again revokes the tokens issued from it (RFC 9700 §4.5) and returns ErrTokenReuse.
func (*Store) Host ¶
Host returns the stored registration for issuer; kind separates loopback and web redirect URIs.
func (*Store) RevokeToken ¶
RevokeToken deletes a token of clientID; revoking a refresh token revokes its whole family.
func (*Store) RotateRefresh ¶
RotateRefresh marks a refresh token of clientID as used and returns its grant. Presenting an already rotated token revokes every token of its family (RFC 9700 §4.14.2).
func (*Store) SaveAccount ¶
SaveAccount creates or replaces the account (user, email) and returns its id.
func (*Store) SaveAuthRequest ¶
SaveAuthRequest stores (or replaces) an encrypted pending authorization request.
func (*Store) SaveClient ¶
SaveClient stores a new client.
func (*Store) SaveToken ¶
func (s *Store) SaveToken(ctx context.Context, token, kind string, g *Grant, ttl time.Duration) error
SaveToken stores an issued token by its hash.
func (*Store) SetDefault ¶
SetDefault marks one account of the user as the default.
func (*Store) StaticHosts ¶
StaticHosts lists the issuers whose registration was entered by the operator.
func (*Store) UpdateToken ¶
UpdateToken replaces the stored token of an account after a refresh.
func (*Store) UpsertUser ¶
UpsertUser returns the id of the user identified by (issuer, subject), creating it if needed.