Add external IdP authentication via OAuth (GitHub) and OIDC (Google, Azure AD). Users can sign in with enterprise credentials; accounts are auto-provisioned and linked on first login. Configured entirely via environment variables. - schema/011_external_auth.sql: user_identities table + email column on users - internal/auth/idp/: provider interface, GitHub OAuth, generic OIDC, store, handlers (list providers, login redirect, callback with auto-provisioning) - internal/auth/user_store.go: GetUserByEmail + SetEmail for IdP linking - cmd/synapbus/main.go: wire IdP routes + agent provisioner adapter - web/src/routes/login/+page.svelte: IdP buttons above password form - Tests: domain restriction, store CRUD, provider listing, user provisioning Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
// Package idp provides enterprise identity provider integrations for SynapBus.
|
|
// Supported providers: GitHub (OAuth), Google (OIDC), Azure AD (OIDC).
|
|
package idp
|
|
|
|
import "context"
|
|
|
|
// Provider is the interface that all identity providers must implement.
|
|
type Provider interface {
|
|
// ID returns the unique identifier for this provider (e.g., "github", "google", "azuread").
|
|
ID() string
|
|
// Type returns the provider type ("oauth" or "oidc").
|
|
Type() string
|
|
// DisplayName returns the human-readable name (e.g., "GitHub", "Google").
|
|
DisplayName() string
|
|
// AuthCodeURL generates the authorization URL with the given state parameter.
|
|
AuthCodeURL(state string) string
|
|
// Exchange trades an authorization code for user information.
|
|
Exchange(ctx context.Context, code string) (*ExternalUser, error)
|
|
}
|
|
|
|
// ExternalUser represents user information obtained from an external identity provider.
|
|
type ExternalUser struct {
|
|
ProviderID string
|
|
ExternalID string
|
|
Email string
|
|
Name string
|
|
Username string
|
|
Groups []string
|
|
RawClaims map[string]any
|
|
}
|
|
|
|
// ProviderInfo is a minimal representation of a provider for API responses.
|
|
type ProviderInfo struct {
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
DisplayName string `json:"display_name"`
|
|
}
|