Documentation
¶
Index ¶
- type AdminAddProviderRequest
- type AdminUpdateProviderRequest
- type AuthURLResponse
- type CallbackDataResponse
- type CallbackRequest
- type CallbackResponse
- type CallbackResult
- type Config
- type ConnectionResponse
- type ConnectionsResponse
- type DashboardExtension
- func (e *DashboardExtension) DashboardWidgets() []ui.DashboardWidget
- func (e *DashboardExtension) ExtensionID() string
- func (e *DashboardExtension) HandleCreateProvider(c forge.Context) error
- func (e *DashboardExtension) HandleDeleteProvider(c forge.Context) error
- func (e *DashboardExtension) HandleToggleProvider(c forge.Context) error
- func (e *DashboardExtension) HandleUpdateProvider(c forge.Context) error
- func (e *DashboardExtension) NavigationItems() []ui.NavigationItem
- func (e *DashboardExtension) Routes() []ui.Route
- func (e *DashboardExtension) ServeProviderAddPage(c forge.Context) error
- func (e *DashboardExtension) ServeProviderEditPage(c forge.Context) error
- func (e *DashboardExtension) ServeProvidersListPage(c forge.Context) error
- func (e *DashboardExtension) SetRegistry(registry *dashboard.ExtensionRegistry)
- func (e *DashboardExtension) SettingsPages() []ui.SettingsPage
- func (e *DashboardExtension) SettingsSections() []ui.SettingsSection
- type ErrorResponse
- type Handler
- func (h *Handler) AdminAddProvider(c forge.Context) error
- func (h *Handler) AdminDeleteProvider(c forge.Context) error
- func (h *Handler) AdminListProviders(c forge.Context) error
- func (h *Handler) AdminUpdateProvider(c forge.Context) error
- func (h *Handler) Callback(c forge.Context) error
- func (h *Handler) LinkAccount(c forge.Context) error
- func (h *Handler) ListProviders(c forge.Context) error
- func (h *Handler) SignIn(c forge.Context) error
- func (h *Handler) UnlinkAccount(c forge.Context) error
- type LinkAccountRequest
- type MemoryStateStore
- type MessageResponse
- type OAuthState
- type Plugin
- func (p *Plugin) DashboardExtension() ui.DashboardExtension
- func (p *Plugin) GetConfigRepository() repository.SocialProviderConfigRepository
- func (p *Plugin) GetService() *Service
- func (p *Plugin) ID() string
- func (p *Plugin) Init(authInst core.Authsome) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
- func (p *Plugin) SetConfig(config Config)
- type PluginOption
- func WithAllowLinking(allow bool) PluginOption
- func WithAutoCreateUser(auto bool) PluginOption
- func WithDefaultConfig(cfg Config) PluginOption
- func WithProvider(name string, clientID, clientSecret, callbackURL string, scopes []string) PluginOption
- func WithTrustEmailVerified(trust bool) PluginOption
- type ProviderConfigResponse
- type ProvidersAppResponse
- type ProvidersConfig
- type ProvidersResponse
- type RateLimit
- type RateLimiter
- type RedisStateStore
- type Service
- func (s *Service) CreateSocialAccount(ctx context.Context, userID, appID xid.ID, userOrganizationID *xid.ID, ...) error
- func (s *Service) GetAuthorizationURL(ctx context.Context, providerName string, appID xid.ID, ...) (string, error)
- func (s *Service) GetLinkAccountURL(ctx context.Context, providerName string, userID xid.ID, appID xid.ID, ...) (string, error)
- func (s *Service) GetProviderConfig(providerName string) *providers.ProviderConfig
- func (s *Service) HandleCallback(ctx context.Context, providerName, stateToken, code string) (*CallbackResult, error)
- func (s *Service) InvalidateEnvironmentCache(appID, envID xid.ID)
- func (s *Service) IsProviderEnabled(providerName string) bool
- func (s *Service) ListProviders(ctx context.Context, appID, envID xid.ID) []string
- func (s *Service) LoadConfigForEnvironment(ctx context.Context, appID, envID xid.ID) error
- func (s *Service) SetConfigRepository(repo repository.SocialProviderConfigRepository)
- func (s *Service) UnlinkAccount(ctx context.Context, userID xid.ID, provider string) error
- type SignInRequest
- type StateStorageConfig
- type StateStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminAddProviderRequest ¶
type AdminAddProviderRequest struct {
AppID xid.ID `json:"appId" validate:"required"`
Provider string `json:"provider" validate:"required" example:"google"`
ClientID string `json:"clientId" validate:"required"`
ClientSecret string `json:"clientSecret" validate:"required"`
Scopes []string `json:"scopes,omitempty"`
Enabled bool `json:"enabled"`
}
type AuthURLResponse ¶
type AuthURLResponse struct {
URL string `json:"url" example:"https://accounts.google.com/o/oauth2/v2/auth?..."`
}
Response types - properly typed
type CallbackDataResponse ¶
type CallbackRequest ¶ added in v0.0.7
type CallbackRequest struct {
Provider string `path:"provider" validate:"required" json:"-"`
State string `query:"state" validate:"required" json:"state"`
Code string `query:"code" json:"code"`
Error string `query:"error" json:"error,omitempty"`
ErrorDescription string `query:"error_description" json:"errorDescription,omitempty"`
}
CallbackRequest represents OAuth callback parameters
type CallbackResponse ¶
type CallbackResult ¶
type CallbackResult struct {
User *user.User // Nil for new users, populated for existing users
OAuthUserInfo *providers.UserInfo // OAuth provider user info (always populated)
OAuthToken *oauth2.Token // OAuth token for linking social account
Provider string // OAuth provider name (e.g., "github", "google")
SocialAccount *schema.SocialAccount
IsNewUser bool
Action string // "signin", "signup", "linked"
AppID xid.ID // App ID from state
UserOrgID *xid.ID // Optional user organization ID from state
}
CallbackResult holds the result of OAuth callback processing
type Config ¶
type Config struct {
// Base URL for OAuth callbacks (e.g., "https://example.com")
BaseURL string `json:"baseUrl" yaml:"baseUrl"`
// Providers configuration
Providers ProvidersConfig `json:"providers" yaml:"providers"`
// Advanced options
AllowAccountLinking bool `json:"allowAccountLinking" yaml:"allowAccountLinking"` // Allow linking multiple providers to one user
AutoCreateUser bool `json:"autoCreateUser" yaml:"autoCreateUser"` // Auto-create user on OAuth sign-in
RequireEmailVerified bool `json:"requireEmailVerified" yaml:"requireEmailVerified"` // Require email verification from provider
TrustEmailVerified bool `json:"trustEmailVerified" yaml:"trustEmailVerified"` // Trust email verification from provider
// State storage configuration
StateStorage StateStorageConfig `json:"stateStorage" yaml:"stateStorage"`
}
Config holds the configuration for social auth providers
type ConnectionResponse ¶
type ConnectionResponse struct {
Connection *base.SocialAccount `json:"connection"`
}
type ConnectionsResponse ¶
type ConnectionsResponse struct {
Connections []*base.SocialAccount `json:"connections"`
}
type DashboardExtension ¶ added in v0.0.3
type DashboardExtension struct {
// contains filtered or unexported fields
}
DashboardExtension implements ui.DashboardExtension for the social plugin
func NewDashboardExtension ¶ added in v0.0.3
func NewDashboardExtension(plugin *Plugin, configRepo repository.SocialProviderConfigRepository) *DashboardExtension
NewDashboardExtension creates a new dashboard extension
func (*DashboardExtension) DashboardWidgets ¶ added in v0.0.3
func (e *DashboardExtension) DashboardWidgets() []ui.DashboardWidget
DashboardWidgets returns dashboard widgets
func (*DashboardExtension) ExtensionID ¶ added in v0.0.3
func (e *DashboardExtension) ExtensionID() string
ExtensionID returns the unique identifier for this extension
func (*DashboardExtension) HandleCreateProvider ¶ added in v0.0.3
func (e *DashboardExtension) HandleCreateProvider(c forge.Context) error
HandleCreateProvider creates a new social provider configuration
func (*DashboardExtension) HandleDeleteProvider ¶ added in v0.0.3
func (e *DashboardExtension) HandleDeleteProvider(c forge.Context) error
HandleDeleteProvider deletes a social provider configuration
func (*DashboardExtension) HandleToggleProvider ¶ added in v0.0.3
func (e *DashboardExtension) HandleToggleProvider(c forge.Context) error
HandleToggleProvider toggles a social provider's enabled status
func (*DashboardExtension) HandleUpdateProvider ¶ added in v0.0.3
func (e *DashboardExtension) HandleUpdateProvider(c forge.Context) error
HandleUpdateProvider updates an existing social provider configuration
func (*DashboardExtension) NavigationItems ¶ added in v0.0.3
func (e *DashboardExtension) NavigationItems() []ui.NavigationItem
NavigationItems returns the navigation items for the dashboard
func (*DashboardExtension) Routes ¶ added in v0.0.3
func (e *DashboardExtension) Routes() []ui.Route
Routes returns the dashboard routes
func (*DashboardExtension) ServeProviderAddPage ¶ added in v0.0.3
func (e *DashboardExtension) ServeProviderAddPage(c forge.Context) error
ServeProviderAddPage renders the add provider form
func (*DashboardExtension) ServeProviderEditPage ¶ added in v0.0.3
func (e *DashboardExtension) ServeProviderEditPage(c forge.Context) error
ServeProviderEditPage renders the edit provider form
func (*DashboardExtension) ServeProvidersListPage ¶ added in v0.0.3
func (e *DashboardExtension) ServeProvidersListPage(c forge.Context) error
ServeProvidersListPage renders the social providers list page
func (*DashboardExtension) SetRegistry ¶ added in v0.0.3
func (e *DashboardExtension) SetRegistry(registry *dashboard.ExtensionRegistry)
SetRegistry sets the extension registry reference (called by dashboard after registration)
func (*DashboardExtension) SettingsPages ¶ added in v0.0.3
func (e *DashboardExtension) SettingsPages() []ui.SettingsPage
SettingsPages returns settings pages for the plugin
func (*DashboardExtension) SettingsSections ¶ added in v0.0.3
func (e *DashboardExtension) SettingsSections() []ui.SettingsSection
SettingsSections returns settings sections (deprecated, using SettingsPages instead)
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for social OAuth
func NewHandler ¶
func NewHandler( service *Service, rateLimiter *RateLimiter, authCompletion *authflow.CompletionService, ) *Handler
NewHandler creates a new social OAuth handler
func (*Handler) AdminAddProvider ¶
AdminAddProvider handles POST /social/admin/providers Adds/configures an OAuth provider for an app
func (*Handler) AdminDeleteProvider ¶
AdminDeleteProvider handles DELETE /social/admin/providers/:provider Removes OAuth provider configuration for an app
func (*Handler) AdminListProviders ¶
AdminListProviders handles GET /social/admin/providers Lists configured OAuth providers for an app
func (*Handler) AdminUpdateProvider ¶
AdminUpdateProvider handles PUT /social/admin/providers/:provider Updates OAuth provider configuration for an app
func (*Handler) Callback ¶
Callback handles OAuth provider callback GET /api/auth/callback/:provider
func (*Handler) LinkAccount ¶
LinkAccount links a social provider to the current user POST /api/auth/account/link
func (*Handler) ListProviders ¶
ListProviders returns available OAuth providers GET /api/auth/providers
type LinkAccountRequest ¶
type MemoryStateStore ¶
type MemoryStateStore struct {
// contains filtered or unexported fields
}
MemoryStateStore is an in-memory implementation of StateStore
func NewMemoryStateStore ¶
func NewMemoryStateStore() *MemoryStateStore
NewMemoryStateStore creates a new in-memory state store
func (*MemoryStateStore) Delete ¶
func (s *MemoryStateStore) Delete(ctx context.Context, key string) error
Delete removes a state
func (*MemoryStateStore) Get ¶
func (s *MemoryStateStore) Get(ctx context.Context, key string) (*OAuthState, error)
Get retrieves a state
func (*MemoryStateStore) Set ¶
func (s *MemoryStateStore) Set(ctx context.Context, key string, state *OAuthState, ttl time.Duration) error
Set stores a state with TTL
type OAuthState ¶
type OAuthState struct {
Provider string `json:"provider"`
AppID xid.ID `json:"app_id"`
UserOrganizationID *xid.ID `json:"user_organization_id,omitempty"`
RedirectURL string `json:"redirect_url,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExtraScopes []string `json:"extra_scopes,omitempty"`
LinkUserID *xid.ID `json:"link_user_id,omitempty"`
}
OAuthState stores temporary OAuth state data
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the social OAuth plugin
func NewPlugin ¶
func NewPlugin(opts ...PluginOption) *Plugin
NewPlugin creates a new social OAuth plugin with optional configuration
func (*Plugin) DashboardExtension ¶ added in v0.0.3
func (p *Plugin) DashboardExtension() ui.DashboardExtension
DashboardExtension returns the dashboard extension for the social plugin
func (*Plugin) GetConfigRepository ¶ added in v0.0.3
func (p *Plugin) GetConfigRepository() repository.SocialProviderConfigRepository
GetConfigRepository returns the config repository (for testing/internal use)
func (*Plugin) GetService ¶
GetService returns the social service (for testing/internal use)
func (*Plugin) RegisterHooks ¶
func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
RegisterHooks registers plugin hooks
func (*Plugin) RegisterRoutes ¶
RegisterRoutes registers the plugin's HTTP routes
func (*Plugin) RegisterServiceDecorators ¶
func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
RegisterServiceDecorators registers service decorators
type PluginOption ¶
type PluginOption func(*Plugin)
PluginOption is a functional option for configuring the social plugin
func WithAllowLinking ¶
func WithAllowLinking(allow bool) PluginOption
WithAllowLinking sets whether to allow account linking
func WithAutoCreateUser ¶
func WithAutoCreateUser(auto bool) PluginOption
WithAutoCreateUser sets whether to auto-create users
func WithDefaultConfig ¶
func WithDefaultConfig(cfg Config) PluginOption
WithDefaultConfig sets the default configuration for the plugin
func WithProvider ¶
func WithProvider(name string, clientID, clientSecret, callbackURL string, scopes []string) PluginOption
WithProvider adds a provider configuration
func WithTrustEmailVerified ¶
func WithTrustEmailVerified(trust bool) PluginOption
WithTrustEmailVerified sets whether to trust provider email verification
type ProviderConfigResponse ¶
type ProvidersAppResponse ¶
type ProvidersConfig ¶
type ProvidersConfig struct {
Google *providers.ProviderConfig `json:"google,omitempty" yaml:"google,omitempty"`
GitHub *providers.ProviderConfig `json:"github,omitempty" yaml:"github,omitempty"`
Microsoft *providers.ProviderConfig `json:"microsoft,omitempty" yaml:"microsoft,omitempty"`
Apple *providers.ProviderConfig `json:"apple,omitempty" yaml:"apple,omitempty"`
Facebook *providers.ProviderConfig `json:"facebook,omitempty" yaml:"facebook,omitempty"`
Discord *providers.ProviderConfig `json:"discord,omitempty" yaml:"discord,omitempty"`
Twitter *providers.ProviderConfig `json:"twitter,omitempty" yaml:"twitter,omitempty"`
LinkedIn *providers.ProviderConfig `json:"linkedin,omitempty" yaml:"linkedin,omitempty"`
Spotify *providers.ProviderConfig `json:"spotify,omitempty" yaml:"spotify,omitempty"`
Twitch *providers.ProviderConfig `json:"twitch,omitempty" yaml:"twitch,omitempty"`
Dropbox *providers.ProviderConfig `json:"dropbox,omitempty" yaml:"dropbox,omitempty"`
GitLab *providers.ProviderConfig `json:"gitlab,omitempty" yaml:"gitlab,omitempty"`
LINE *providers.ProviderConfig `json:"line,omitempty" yaml:"line,omitempty"`
Reddit *providers.ProviderConfig `json:"reddit,omitempty" yaml:"reddit,omitempty"`
Slack *providers.ProviderConfig `json:"slack,omitempty" yaml:"slack,omitempty"`
Bitbucket *providers.ProviderConfig `json:"bitbucket,omitempty" yaml:"bitbucket,omitempty"`
Notion *providers.ProviderConfig `json:"notion,omitempty" yaml:"notion,omitempty"`
}
ProvidersConfig holds configuration for each provider
type ProvidersResponse ¶
type ProvidersResponse struct {
Providers []string `json:"providers" example:"[\"google\",\"github\",\"facebook\"]"`
}
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides rate limiting for OAuth endpoints
func NewRateLimiter ¶
func NewRateLimiter(redisClient *redis.Client) *RateLimiter
NewRateLimiter creates a new rate limiter
type RedisStateStore ¶
type RedisStateStore struct {
// contains filtered or unexported fields
}
RedisStateStore is a Redis-backed implementation of StateStore
func NewRedisStateStore ¶
func NewRedisStateStore(client *redis.Client) *RedisStateStore
NewRedisStateStore creates a new Redis state store
func (*RedisStateStore) Delete ¶
func (s *RedisStateStore) Delete(ctx context.Context, key string) error
Delete removes a state from Redis
func (*RedisStateStore) Get ¶
func (s *RedisStateStore) Get(ctx context.Context, key string) (*OAuthState, error)
Get retrieves a state from Redis
func (*RedisStateStore) Set ¶
func (s *RedisStateStore) Set(ctx context.Context, key string, state *OAuthState, ttl time.Duration) error
Set stores a state with TTL in Redis
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles social OAuth flows
func NewService ¶
func NewService(config Config, socialRepo repository.SocialAccountRepository, userSvc *user.Service, stateStore StateStore, auditSvc *audit.Service) *Service
NewService creates a new social auth service
func (*Service) CreateSocialAccount ¶ added in v0.0.7
func (s *Service) CreateSocialAccount(ctx context.Context, userID, appID xid.ID, userOrganizationID *xid.ID, provider string, userInfo *providers.UserInfo, token *oauth2.Token) error
CreateSocialAccount creates a new social account record This is called after user creation to link the OAuth provider
func (*Service) GetAuthorizationURL ¶
func (s *Service) GetAuthorizationURL(ctx context.Context, providerName string, appID xid.ID, userOrganizationID *xid.ID, extraScopes []string) (string, error)
GetAuthorizationURL generates an OAuth authorization URL
func (*Service) GetLinkAccountURL ¶
func (s *Service) GetLinkAccountURL(ctx context.Context, providerName string, userID xid.ID, appID xid.ID, userOrganizationID *xid.ID, extraScopes []string) (string, error)
GetLinkAccountURL generates a URL to link an additional provider to an existing user
func (*Service) GetProviderConfig ¶ added in v0.0.3
func (s *Service) GetProviderConfig(providerName string) *providers.ProviderConfig
GetProviderConfig returns the current provider configuration for a specific provider This can be used to inspect what's currently configured
func (*Service) HandleCallback ¶
func (s *Service) HandleCallback(ctx context.Context, providerName, stateToken, code string) (*CallbackResult, error)
HandleCallback processes the OAuth callback
func (*Service) InvalidateEnvironmentCache ¶ added in v0.0.7
InvalidateEnvironmentCache clears the cache for a specific environment This should be called when provider configurations are updated
func (*Service) IsProviderEnabled ¶ added in v0.0.3
IsProviderEnabled checks if a provider is currently enabled and configured
func (*Service) ListProviders ¶
ListProviders returns available providers for a specific environment
func (*Service) LoadConfigForEnvironment ¶ added in v0.0.3
LoadConfigForEnvironment loads provider configurations from the database for a specific environment and merges them with the current configuration. DB configs take precedence over code-based configs.
func (*Service) SetConfigRepository ¶ added in v0.0.3
func (s *Service) SetConfigRepository(repo repository.SocialProviderConfigRepository)
SetConfigRepository sets the config repository for DB-backed configuration
type SignInRequest ¶
type SignInRequest struct {
Provider string `json:"provider" validate:"required" example:"google"`
Scopes []string `json:"scopes,omitempty" example:"[\"email\",\"profile\"]"`
RedirectURL string `json:"redirectUrl,omitempty" example:"https://example.com/auth/callback"`
}
Request types
type StateStorageConfig ¶
type StateStorageConfig struct {
// UseRedis enables Redis-backed state storage (recommended for production)
UseRedis bool `json:"useRedis" yaml:"useRedis"`
// RedisAddr is the Redis server address
RedisAddr string `json:"redisAddr" yaml:"redisAddr"`
// RedisPassword is the Redis password (optional)
RedisPassword string `json:"redisPassword" yaml:"redisPassword"`
// RedisDB is the Redis database number
RedisDB int `json:"redisDb" yaml:"redisDb"`
// StateTTL is the state expiration time
StateTTL time.Duration `json:"stateTtl" yaml:"stateTtl"`
}
StateStorageConfig holds configuration for OAuth state storage