Documentation
¶
Index ¶
- func FetchUserInfo(ctx context.Context, client *http.Client, logger models.Logger, ...) (map[string]any, error)
- func FetchUserInfoPost(ctx context.Context, client *http.Client, logger models.Logger, ...) (map[string]any, error)
- func GetBoolField(data map[string]any, field string) bool
- func GetIDField(data map[string]any, field string) (string, error)
- func GetStringField(data map[string]any, field string) string
- func ResolveAuthURLParams(cfg types.ProviderConfig, defaults ProviderDefaults) map[string]string
- func ResolveOAuth2Config(cfg types.ProviderConfig, defaults ProviderDefaults) *oauth2.Config
- func ResolveUserInfoURL(cfg types.ProviderConfig, defaultURL string) string
- func ValidateAuthURLParams(params map[string]string) error
- func ValidateProviderName(name string) error
- type BaseProvider
- func (p *BaseProvider) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p *BaseProvider) GetAuthURL(state string, opts ...oauth2.AuthCodeOption) string
- func (p *BaseProvider) GetConfig() *oauth2.Config
- func (p *BaseProvider) Name() string
- func (p *BaseProvider) RequiresPKCE() bool
- type DiscordOAuth2Provider
- type DropboxOAuth2Provider
- type GenericOAuth2Provider
- type GitHubOAuth2Provider
- type GoogleOAuth2Provider
- type MicrosoftOAuth2Provider
- type NotionOAuth2Provider
- func (p *NotionOAuth2Provider) Exchange(ctx context.Context, code string, _ ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (p *NotionOAuth2Provider) GetAuthURL(state string, opts ...oauth2.AuthCodeOption) string
- func (p *NotionOAuth2Provider) GetUserInfo(_ context.Context, token *oauth2.Token) (*types.UserInfo, error)
- type ProviderDefaults
- type ProviderOptions
- type ProviderRegistry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchUserInfo ¶
func FetchUserInfo(ctx context.Context, client *http.Client, logger models.Logger, token *oauth2.Token, url string) (map[string]any, error)
FetchUserInfo fetches and parses user info with a bounded response body.
func FetchUserInfoPost ¶ added in v1.51.0
func FetchUserInfoPost(ctx context.Context, client *http.Client, logger models.Logger, token *oauth2.Token, url string) (map[string]any, error)
FetchUserInfoPost fetches and parses user info using a POST request with an empty JSON object body.
func GetBoolField ¶ added in v1.50.0
GetBoolField safely gets a boolean field from a map.
func GetIDField ¶ added in v1.50.0
GetIDField returns a canonical string representation of an identifier field. Numeric IDs are kept as integers instead of being formatted through float64.
func GetStringField ¶
GetStringField safely gets a string field from a map.
func ResolveAuthURLParams ¶ added in v1.51.0
func ResolveAuthURLParams(cfg types.ProviderConfig, defaults ProviderDefaults) map[string]string
ResolveAuthURLParams merges provider defaults with operator configuration. Configuration overrides defaults, and an empty configured value removes a default. The defaults map is never mutated.
func ResolveOAuth2Config ¶ added in v1.50.0
func ResolveOAuth2Config(cfg types.ProviderConfig, defaults ProviderDefaults) *oauth2.Config
ResolveOAuth2Config applies a provider config on top of built-in defaults.
func ResolveUserInfoURL ¶ added in v1.50.0
func ResolveUserInfoURL(cfg types.ProviderConfig, defaultURL string) string
ResolveUserInfoURL returns the configured user info URL or the provider default.
func ValidateAuthURLParams ¶ added in v1.51.0
ValidateAuthURLParams rejects blank and protocol-managed parameter names. Values are strings, so URL query encoding is the only handling they need.
func ValidateProviderName ¶ added in v1.50.1
ValidateProviderName enforces a path-safe provider identifier.
Types ¶
type BaseProvider ¶
type BaseProvider struct {
// contains filtered or unexported fields
}
BaseProvider provides common functionality for OAuth2 providers
func NewBaseProvider ¶
func NewBaseProvider(name string, config *oauth2.Config, opts *ProviderOptions, pkce bool, authURLParams map[string]string) *BaseProvider
NewBaseProvider creates a new base provider
func (*BaseProvider) Exchange ¶
func (p *BaseProvider) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
Exchange exchanges the authorization code for a token
func (*BaseProvider) GetAuthURL ¶
func (p *BaseProvider) GetAuthURL(state string, opts ...oauth2.AuthCodeOption) string
GetAuthURL returns the authorization URL.
func (*BaseProvider) GetConfig ¶
func (p *BaseProvider) GetConfig() *oauth2.Config
GetConfig returns the oauth2 config
func (*BaseProvider) RequiresPKCE ¶
func (p *BaseProvider) RequiresPKCE() bool
RequiresPKCE returns whether the provider requires PKCE
type DiscordOAuth2Provider ¶ added in v1.50.0
type DiscordOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
func NewDiscordOAuth2Provider ¶ added in v1.50.0
func NewDiscordOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *DiscordOAuth2Provider
func (*DiscordOAuth2Provider) GetUserInfo ¶ added in v1.50.0
type DropboxOAuth2Provider ¶ added in v1.51.0
type DropboxOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
DropboxOAuth2Provider implements OAuth2Provider for Dropbox OpenID Connect.
func NewDropboxOAuth2Provider ¶ added in v1.51.0
func NewDropboxOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *DropboxOAuth2Provider
NewDropboxOAuth2Provider creates a new Dropbox OAuth2 provider.
func (*DropboxOAuth2Provider) GetUserInfo ¶ added in v1.51.0
func (p *DropboxOAuth2Provider) GetUserInfo(ctx context.Context, token *oauth2.Token) (*types.UserInfo, error)
GetUserInfo fetches and normalizes Dropbox OpenID Connect user information.
type GenericOAuth2Provider ¶ added in v1.50.0
type GenericOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
GenericOAuth2Provider implements OAuth2Provider for custom OIDC/OAuth2 endpoints
func NewGenericOAuth2Provider ¶ added in v1.50.0
func NewGenericOAuth2Provider(name string, cfg types.ProviderConfig, opts *ProviderOptions) *GenericOAuth2Provider
NewGenericOAuth2Provider creates a new generic OAuth2 provider
func (*GenericOAuth2Provider) GetUserInfo ¶ added in v1.50.0
func (p *GenericOAuth2Provider) GetUserInfo(ctx context.Context, token *oauth2.Token) (*types.UserInfo, error)
GetUserInfo fetches and normalizes user information using custom field mapping
type GitHubOAuth2Provider ¶ added in v1.50.0
type GitHubOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
func NewGitHubOAuth2Provider ¶ added in v1.50.0
func NewGitHubOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *GitHubOAuth2Provider
func (*GitHubOAuth2Provider) GetUserInfo ¶ added in v1.50.0
type GoogleOAuth2Provider ¶ added in v1.51.0
type GoogleOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
func NewGoogleOAuth2Provider ¶ added in v1.51.0
func NewGoogleOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *GoogleOAuth2Provider
func (*GoogleOAuth2Provider) GetUserInfo ¶ added in v1.51.0
type MicrosoftOAuth2Provider ¶ added in v1.51.0
type MicrosoftOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
MicrosoftOAuth2Provider implements OAuth2Provider for Microsoft Entra ID (work/school and personal accounts)
func NewMicrosoftOAuth2Provider ¶ added in v1.51.0
func NewMicrosoftOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *MicrosoftOAuth2Provider
NewMicrosoftOAuth2Provider creates a new Microsoft OAuth2 provider.
func (*MicrosoftOAuth2Provider) GetUserInfo ¶ added in v1.51.0
func (p *MicrosoftOAuth2Provider) GetUserInfo(ctx context.Context, token *oauth2.Token) (*types.UserInfo, error)
GetUserInfo fetches and normalizes Microsoft Graph user information
type NotionOAuth2Provider ¶ added in v1.51.0
type NotionOAuth2Provider struct {
*BaseProvider
// contains filtered or unexported fields
}
NotionOAuth2Provider implements OAuth2Provider for Notion
func NewNotionOAuth2Provider ¶ added in v1.51.0
func NewNotionOAuth2Provider(cfg types.ProviderConfig, opts *ProviderOptions) *NotionOAuth2Provider
NewNotionOAuth2Provider creates a new Notion OAuth2 provider.
func (*NotionOAuth2Provider) Exchange ¶ added in v1.51.0
func (p *NotionOAuth2Provider) Exchange(ctx context.Context, code string, _ ...oauth2.AuthCodeOption) (*oauth2.Token, error)
Exchange exchanges the authorization code for a token.
Notion requires HTTP Basic credentials and a JSON body, while x/oauth2 always sends a form-encoded body, so the request is built here. The authorize-step options cannot be applied to it either: oauth2.AuthCodeOption only exposes an unexported setter, and Notion needs none of them.
func (*NotionOAuth2Provider) GetAuthURL ¶ added in v1.51.0
func (p *NotionOAuth2Provider) GetAuthURL(state string, opts ...oauth2.AuthCodeOption) string
GetAuthURL adds owner=user, which makes Notion return the authorizing person rather than a workspace-owned token.
func (*NotionOAuth2Provider) GetUserInfo ¶ added in v1.51.0
func (p *NotionOAuth2Provider) GetUserInfo(_ context.Context, token *oauth2.Token) (*types.UserInfo, error)
GetUserInfo maps the owner object returned with the token. Notion exposes no endpoint for the authorizing person, so this performs no HTTP request.
type ProviderDefaults ¶ added in v1.50.0
type ProviderDefaults struct {
Endpoint oauth2.Endpoint
Scopes []string
UserInfoURL string
AuthURLParams map[string]string
}
ProviderDefaults describes the built-in behaviour of a provider before config overrides.
type ProviderOptions ¶ added in v1.50.0
ProviderOptions carries optional dependencies shared by providers.
type ProviderRegistry ¶
type ProviderRegistry struct {
// contains filtered or unexported fields
}
ProviderRegistry manages OAuth2 providers
func NewProviderRegistry ¶
func NewProviderRegistry() *ProviderRegistry
NewProviderRegistry creates a new provider registry
func (*ProviderRegistry) Get ¶
func (r *ProviderRegistry) Get(name string) (types.OAuth2Provider, bool)
Get retrieves a provider by name
func (*ProviderRegistry) GetAll ¶
func (r *ProviderRegistry) GetAll() map[string]types.OAuth2Provider
GetAll returns all registered providers
func (*ProviderRegistry) Names ¶ added in v1.50.0
func (r *ProviderRegistry) Names() []string
Names returns the registered provider names in deterministic order.
func (*ProviderRegistry) Register ¶
func (r *ProviderRegistry) Register(name string, provider types.OAuth2Provider) error
Register registers a provider