Documentation
¶
Index ¶
- Constants
- func EncodeOAuthState(s *OAuthState) string
- type OAuthState
- type OIDCAuth
- type OIDCOption
- type UserAuth
- func (ua *UserAuth) AuthenticateRequest(r *http.Request) *identity.User
- func (ua *UserAuth) HandleAgentActivity(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleCallback(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleCreateAPIKey(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleDashboardAgents(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleDashboardStats(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleDeleteAPIKey(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleDeleteAgent(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleListAPIKeys(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleLogout(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleMe(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleUpdateAgent(w http.ResponseWriter, r *http.Request)
- func (ua *UserAuth) HandleUpdateMe(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( SessionCookieName = "e2a_session" StateCookieName = "e2a_oauth_state" SessionMaxAge = 7 * 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func EncodeOAuthState ¶
func EncodeOAuthState(s *OAuthState) string
Types ¶
type OAuthState ¶
type OAuthState struct {
Nonce string `json:"n"`
CLICallback string `json:"cb,omitempty"`
CLIState string `json:"cs,omitempty"`
ReturnTo string `json:"rt,omitempty"`
}
OAuthState is encoded into the OAuth state parameter. It carries the CSRF nonce and, for CLI-initiated logins, the callback URL and CLI state token. ReturnTo, if set, is a same-origin server-path the user is bounced back to after callback succeeds — used by the MCP authorize flow to resume after a session is established. Validated at HandleLogin time.
type OIDCAuth ¶
type OIDCAuth struct {
// contains filtered or unexported fields
}
OIDCAuth implements an optional OpenID Connect relying party for browser login. It accepts only Authorization Code responses initiated by HandleLogin, verifies the returned ID token, and maps a configured claim to an existing e2a users.id. It never provisions users.
func NewOIDCAuth ¶
func NewOIDCAuth(ctx context.Context, cfg config.OIDCConfig, store *identity.Store, production bool, baseURL string, opts ...OIDCOption) (*OIDCAuth, error)
NewOIDCAuth returns nil without performing discovery when OIDC is disabled. Enabled configurations construct the handler synchronously -- this call never touches the network -- and start one background goroutine that discovers the issuer immediately, then retries with exponential backoff (capped, forever) until it succeeds or ctx is cancelled. Until discovery succeeds, HandleLogin and HandleCallback fail closed with 503. This keeps e2a's boot decoupled from the identity provider's availability (an unreachable issuer no longer prevents the whole process -- mail included -- from starting) while preserving fail-closed login behavior: there is no window where login silently no-ops or half-completes.
Static/config-shaped problems are not this function's concern: they are caught by config.OIDCConfig validation before this is ever called. Only the network-dependent discovery call moved off the boot path.
func (*OIDCAuth) HandleCallback ¶
func (oa *OIDCAuth) HandleCallback(w http.ResponseWriter, r *http.Request)
HandleCallback validates the browser transaction, exchanges the short-lived authorization code over the back channel, verifies the ID token, and creates the same e2a session used by the legacy Google flow. Until background issuer discovery has completed at least once, this fails closed with 503.
func (*OIDCAuth) HandleLogin ¶
func (oa *OIDCAuth) HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLogin creates a browser-bound OIDC transaction and redirects to the provider's authorization endpoint. The PKCE verifier and OIDC nonce never appear in application logs or identity-bearing cookies. Until background issuer discovery has completed at least once, this fails closed with 503 rather than attempting a partial or misconfigured flow.
type OIDCOption ¶
type OIDCOption func(*OIDCAuth)
OIDCOption configures optional, non-default behavior of NewOIDCAuth. Production callers don't need any; they exist for tests that need the background discovery retry loop to run on a compressed timescale, or to observe the loop's lifecycle without a sleep-based race.
func WithOIDCDiscoveryAttemptTimeout ¶
func WithOIDCDiscoveryAttemptTimeout(timeout time.Duration) OIDCOption
WithOIDCDiscoveryAttemptTimeout overrides the maximum duration of one issuer discovery HTTP request (production default: 10s). Intended for tests that exercise a provider which accepts a connection but never responds.
func WithOIDCDiscoveryBackoff ¶
func WithOIDCDiscoveryBackoff(initial, maxBackoff time.Duration) OIDCOption
WithOIDCDiscoveryBackoff overrides the discovery retry loop's initial and maximum backoff durations (production defaults: 1s initial, doubling, capped at 60s). Intended for tests exercising the retry path against a short-lived httptest server, where waiting out the real defaults would make the suite slow.
func WithOIDCDiscoveryDone ¶
func WithOIDCDiscoveryDone(done chan<- struct{}) OIDCOption
WithOIDCDiscoveryDone registers a channel that the background discovery goroutine closes when it returns, whether that's because discovery succeeded or because ctx was cancelled. It exists so tests can assert the goroutine actually exits (no leak) without guessing at a sleep duration.
type UserAuth ¶
type UserAuth struct {
// contains filtered or unexported fields
}
func NewUserAuth ¶
func NewUserAuthWithOAuthConfig ¶
func NewUserAuthWithOAuthConfig(cfg *config.OAuthConfig, oauthCfg *oauth2.Config, store *identity.Store, production bool, userInfoURL string) *UserAuth
NewUserAuthWithOAuthConfig creates a UserAuth with a custom oauth2.Config and userinfo URL. This is intended for testing against fake OAuth servers.
func (*UserAuth) AuthenticateRequest ¶
AuthenticateRequest extracts the user from the session cookie. Returns nil if not authenticated.
func (*UserAuth) HandleAgentActivity ¶
func (ua *UserAuth) HandleAgentActivity(w http.ResponseWriter, r *http.Request)
HandleAgentActivity returns recent message activity for an agent owned by the authenticated user.
func (*UserAuth) HandleCallback ¶
func (ua *UserAuth) HandleCallback(w http.ResponseWriter, r *http.Request)
HandleCallback processes the Google OAuth callback and creates a session.
func (*UserAuth) HandleCreateAPIKey ¶
func (ua *UserAuth) HandleCreateAPIKey(w http.ResponseWriter, r *http.Request)
HandleCreateAPIKey creates a new API key for the authenticated user.
func (*UserAuth) HandleDashboardAgents ¶
func (ua *UserAuth) HandleDashboardAgents(w http.ResponseWriter, r *http.Request)
HandleDashboardAgents lists agents owned by the authenticated user.
func (*UserAuth) HandleDashboardStats ¶
func (ua *UserAuth) HandleDashboardStats(w http.ResponseWriter, r *http.Request)
HandleDashboardStats returns the workspace-level aggregates for the redesigned dashboard's stats strip. Accepts ?window=N (days) to vary the lookback for inbound/outbound totals + delivery success — the dashboard at-a-glance strip omits it (defaults to 7), the settings usage card passes ?window=30. Invalid/out-of-range values fall back to the store's defaults (see DashboardDefaultWindowDays / DashboardMaxWindowDays). See identity.GetDashboardStats for the data sources and graceful-degradation behavior when usage tracking is disabled.
func (*UserAuth) HandleDeleteAPIKey ¶
func (ua *UserAuth) HandleDeleteAPIKey(w http.ResponseWriter, r *http.Request)
HandleDeleteAPIKey deletes an API key owned by the authenticated user.
func (*UserAuth) HandleDeleteAgent ¶
func (ua *UserAuth) HandleDeleteAgent(w http.ResponseWriter, r *http.Request)
HandleDeleteAgent moves an agent owned by the authenticated user to the trash (soft delete — restorable for identity.TrashRetention, then purged by the janitor). Kept in lockstep with the /v1 deleteAgent default semantics.
func (*UserAuth) HandleListAPIKeys ¶
func (ua *UserAuth) HandleListAPIKeys(w http.ResponseWriter, r *http.Request)
HandleListAPIKeys lists API keys for the authenticated user (without key values).
func (*UserAuth) HandleLogin ¶
func (ua *UserAuth) HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLogin redirects the user to Google OAuth. CLI login params (cli_callback, cli_state) are encoded into the OAuth state parameter so they survive the redirect through Google without relying on cookies. return_to (optional) is a same-origin server path the user resumes on after callback success — only paths under /oauth2/ are permitted, used to bounce MCP OAuth clients back into /oauth2/authorize after a session is created.
func (*UserAuth) HandleLogout ¶
func (ua *UserAuth) HandleLogout(w http.ResponseWriter, r *http.Request)
HandleLogout deletes the session and clears the cookie.
func (*UserAuth) HandleMe ¶
func (ua *UserAuth) HandleMe(w http.ResponseWriter, r *http.Request)
HandleMe returns the current authenticated user's info.
func (*UserAuth) HandleUpdateAgent ¶
func (ua *UserAuth) HandleUpdateAgent(w http.ResponseWriter, r *http.Request)
HandleUpdateAgent updates an agent owned by the authenticated user.
func (*UserAuth) HandleUpdateMe ¶
func (ua *UserAuth) HandleUpdateMe(w http.ResponseWriter, r *http.Request)