Documentation
¶
Index ¶
- func Bearer(ctx context.Context) string
- func CanonicalUserID(ctx context.Context) string
- func EffectiveUserID(ctx context.Context) string
- func EnsureUser(ctx context.Context, cfg *Config) context.Context
- func IDToken(ctx context.Context) string
- func MCPAuthToken(ctx context.Context, useIDToken bool) string
- func Provider(ctx context.Context) string
- func TokensFromContext(ctx context.Context) *scyauth.Token
- func WithBearer(ctx context.Context, token string) context.Context
- func WithCanonicalUserID(ctx context.Context, id string) context.Context
- func WithIDToken(ctx context.Context, token string) context.Context
- func WithProvider(ctx context.Context, provider string) context.Context
- func WithTokens(ctx context.Context, t *scyauth.Token) context.Context
- func WithUserInfo(ctx context.Context, info *UserInfo) context.Context
- func WithoutTokens(ctx context.Context) context.Context
- type Config
- type JWT
- type Local
- type OAuth
- type OAuthClient
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalUserID ¶ added in v0.1.29
CanonicalUserID returns the canonical Agently users.id from context, or an empty string when no canonical owner has been resolved. Callers persisting delegated (per-provider) credentials must fail closed on empty results and must never fall back to EffectiveUserID.
func EffectiveUserID ¶
EffectiveUserID returns a stable user identifier from context (subject or email). Returns empty string when no identity is present.
func EnsureUser ¶
EnsureUser populates a user identity in context when missing using config fallbacks (e.g., local mode default username). Returns the original context when no action is needed.
func MCPAuthToken ¶
MCPAuthToken selects a single token string suitable for outbound MCP calls. When useIDToken is true, it prefers a live IDToken and falls back to the access token or legacy bearer when the ID token has expired. When false, it prefers AccessToken and falls back to the legacy bearer key.
func TokensFromContext ¶
TokensFromContext returns the token bundle from context, if present.
func WithBearer ¶
WithBearer stores a raw bearer token in context.
func WithCanonicalUserID ¶ added in v0.1.29
WithCanonicalUserID stores the canonical Agently users.id resolved for the verified workspace identity. It is a persistence identity only: it never replaces EffectiveUserID, which stays on the workspace provider subject/email for the entire request lifetime.
func WithIDToken ¶
WithIDToken stores a raw ID token in context.
func WithProvider ¶ added in v0.1.5
WithProvider stores an auth provider name in context.
func WithTokens ¶
WithTokens stores a token bundle in context.
func WithUserInfo ¶
WithUserInfo stores identity data in context.
func WithoutTokens ¶ added in v0.1.22
WithoutTokens returns a child context that masks token and downstream auth values inherited from its parent. It is used when stale credentials must be preserved in storage but must not be sent to downstream services.
Types ¶
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled" json:"enabled"`
CookieName string `yaml:"cookieName" json:"cookieName"`
SessionTTLHours int `yaml:"sessionTTLHours,omitempty" json:"sessionTTLHours,omitempty"` // cookie/session lifetime; default 168h (7 days)
DefaultUsername string `yaml:"defaultUsername" json:"defaultUsername"`
IpHashKey string `yaml:"ipHashKey" json:"ipHashKey"`
TrustedProxies []string `yaml:"trustedProxies" json:"trustedProxies"`
RedirectPath string `yaml:"redirectPath" json:"redirectPath"`
// New unified model
OAuth *OAuth `yaml:"oauth" json:"oauth"`
Local *Local `yaml:"local" json:"local"`
JWT *JWT `yaml:"jwt" json:"jwt,omitempty"`
}
Config defines global authentication settings. Modes:
- local : username-only with HttpOnly session cookie
- bff : backend-for-frontend OAuth (PKCE) setting HttpOnly cookie
- oidc : frontend obtains tokens and calls APIs with Bearer; server validates
- mixed : accept both Bearer and cookie
- jwt : private/public key JWT — server signs tokens and verifies with RSA/HMAC
func (*Config) IsBearerAccepted ¶
IsBearerAccepted returns true when a Bearer token is an acceptable auth credential given the current configuration.
func (*Config) IsCookieAccepted ¶
IsCookieAccepted returns true when a session cookie is an acceptable auth credential given the current configuration.
func (*Config) IsJWTAuth ¶
IsJWTAuth returns true when auth is enabled and JWT (private/public key) mode is the active auth mechanism.
func (*Config) IsLocalAuth ¶
IsLocalAuth returns true when auth is enabled and the effective mode is local-only (i.e. cookie-based session, no OAuth mode configured).
type JWT ¶
type JWT struct {
Enabled bool `yaml:"enabled" json:"enabled"`
// RSA holds one or more scy resource URLs pointing to RSA public keys (PEM).
// Example: "/path/to/public.pem" or "scy://secret/public_key|blowfish://default"
RSA []string `yaml:"rsa,omitempty" json:"rsa,omitempty"`
// HMAC is a scy resource URL pointing to the HMAC shared secret.
HMAC string `yaml:"hmac,omitempty" json:"hmac,omitempty"`
// CertURL is a JWKS endpoint URL for key discovery (alternative to RSA/HMAC).
CertURL string `yaml:"certURL,omitempty" json:"certURL,omitempty"`
// RSAPrivateKey is a scy resource URL pointing to the RSA private key for signing.
// Only needed when the server itself signs tokens (e.g. for local JWT issuance).
RSAPrivateKey string `yaml:"rsaPrivateKey,omitempty" json:"rsaPrivateKey,omitempty"`
}
JWT configures private/public key JWT authentication. When enabled, Bearer tokens are cryptographically verified using the configured RSA public keys or HMAC secret (via scy/auth/jwt/verifier).
type OAuth ¶
type OAuth struct {
Mode string `yaml:"mode" json:"mode"` // bearer|spa|bff|mixed
Name string `yaml:"name" json:"name"`
Label string `yaml:"label" json:"label"`
Client *OAuthClient `yaml:"client" json:"client"`
}
New unified structures
type OAuthClient ¶
type OAuthClient struct {
ConfigURL string `yaml:"configURL" json:"configURL"` // for bff
DiscoveryURL string `yaml:"discoveryURL" json:"discoveryURL"` // for spa/bearer
JWKSURL string `yaml:"jwksURL" json:"jwksURL"` // for bearer verifier
RedirectURI string `yaml:"redirectURI" json:"redirectURI"`
ClientID string `yaml:"clientID" json:"clientID"`
Scopes []string `yaml:"scopes" json:"scopes"`
WebUIScopes []string `yaml:"webUIScopes,omitempty" json:"webUIScopes,omitempty"`
MobileUIScopes []string `yaml:"mobileUIScopes,omitempty" json:"mobileUIScopes,omitempty"`
CLIScopes []string `yaml:"cliScopes,omitempty" json:"cliScopes,omitempty"`
Issuer string `yaml:"issuer" json:"issuer"` // optional expected iss claim
Audiences []string `yaml:"audiences" json:"audiences"` // optional expected aud claim(s)
}