Documentation
¶
Index ¶
- Variables
- func GenerateState() (string, error)
- type CustomProvider
- type GitHubProvider
- type GoogleProvider
- type Manager
- func (m *Manager) AddProvider(provider Provider)
- func (m *Manager) Exchange(ctx context.Context, providerName, code string) (*oauth2.Token, error)
- func (m *Manager) ExchangeWithRedirect(ctx context.Context, providerName, code, redirectURL string) (*oauth2.Token, error)
- func (m *Manager) GetAuthURL(providerName, state string) (string, error)
- func (m *Manager) GetAuthURLWithHost(providerName, state, hostOrBaseURL, authPathPrefix string) (string, error)deprecated
- func (m *Manager) GetAuthURLWithRedirect(providerName, state, hostOrBaseURL, authPathPrefix string) (string, string, error)
- func (m *Manager) GetProvider(name string) (Provider, error)
- func (m *Manager) GetProviders() []Provider
- func (m *Manager) GetUserEmail(ctx context.Context, providerName string, token *oauth2.Token) (string, error)
- func (m *Manager) GetUserInfo(ctx context.Context, providerName string, token *oauth2.Token) (*UserInfo, error)
- type MicrosoftProvider
- type Provider
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrProviderNotFound is returned when a provider is not found ErrProviderNotFound = errors.New("OAuth2 provider not found") // ErrEmailNotAvailable is returned when the OAuth2 provider does not provide an email address ErrEmailNotAvailable = errors.New("OAuth2 provider did not provide an email address") )
var ( // ErrInvalidToken is returned when the OAuth2 token is invalid ErrInvalidToken = errors.New("invalid OAuth2 token") // ErrEmailNotFound is returned when user email is not found in OAuth2 response ErrEmailNotFound = errors.New("user email not found in OAuth2 response") )
Functions ¶
func GenerateState ¶
GenerateState generates a random state string for CSRF protection
Types ¶
type CustomProvider ¶
type CustomProvider struct {
// contains filtered or unexported fields
}
CustomProvider is a generic OAuth2 provider for custom/OIDC-compatible servers
func NewCustomProvider ¶
func NewCustomProvider( name string, clientID string, clientSecret string, redirectURL string, authURL string, tokenURL string, userInfoURL string, scopes []string, insecureSkipVerify bool, ) *CustomProvider
NewCustomProvider creates a new custom OAuth2 provider
func (*CustomProvider) Config ¶
func (p *CustomProvider) Config() *oauth2.Config
Config returns the OAuth2 config
func (*CustomProvider) GetUserEmail ¶
GetUserEmail retrieves the user's email from the custom provider (deprecated, use GetUserInfo)
func (*CustomProvider) GetUserInfo ¶
GetUserInfo retrieves the user's information from the custom provider
type GitHubProvider ¶
type GitHubProvider struct {
// contains filtered or unexported fields
}
GitHubProvider is the OAuth2 provider for GitHub
func NewGitHubProvider ¶
func NewGitHubProvider(clientID, clientSecret, redirectURL string, scopes []string, resetScopes bool) *GitHubProvider
NewGitHubProvider creates a new GitHub OAuth2 provider
func (*GitHubProvider) Config ¶
func (p *GitHubProvider) Config() *oauth2.Config
Config returns the OAuth2 config
func (*GitHubProvider) GetUserEmail ¶
GetUserEmail retrieves the user's email from GitHub (deprecated, use GetUserInfo)
func (*GitHubProvider) GetUserInfo ¶
GetUserInfo retrieves the user's information from GitHub
type GoogleProvider ¶
type GoogleProvider struct {
// contains filtered or unexported fields
}
GoogleProvider is the OAuth2 provider for Google
func NewGoogleProvider ¶
func NewGoogleProvider(clientID, clientSecret, redirectURL string, scopes []string, resetScopes bool) *GoogleProvider
NewGoogleProvider creates a new Google OAuth2 provider
func (*GoogleProvider) Config ¶
func (p *GoogleProvider) Config() *oauth2.Config
Config returns the OAuth2 config
func (*GoogleProvider) GetUserEmail ¶
GetUserEmail retrieves the user's email from Google (deprecated, use GetUserInfo)
func (*GoogleProvider) GetUserInfo ¶
GetUserInfo retrieves the user's information from Google
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages OAuth2 providers and authentication flow
func (*Manager) AddProvider ¶
AddProvider adds a provider to the manager
func (*Manager) ExchangeWithRedirect ¶
func (m *Manager) ExchangeWithRedirect(ctx context.Context, providerName, code, redirectURL string) (*oauth2.Token, error)
ExchangeWithRedirect exchanges an authorization code for a token using a custom redirect URL. This is required when the redirect URL used in the authorization request differs from the provider's configured redirect URL (e.g., in Docker environments with port mapping).
func (*Manager) GetAuthURL ¶
GetAuthURL generates an authorization URL for a provider
func (*Manager) GetAuthURLWithHost
deprecated
func (m *Manager) GetAuthURLWithHost(providerName, state, hostOrBaseURL, authPathPrefix string) (string, error)
GetAuthURLWithHost generates an authorization URL for a provider with a custom redirect URL based on the request host or base URL. This is useful for dynamic port mapping (e.g., Docker environments). The hostOrBaseURL parameter can be:
- A full base URL (e.g., "http://localhost:4182")
- A host with port (e.g., "localhost:4182")
- Just a host (e.g., "example.com")
Deprecated: Use GetAuthURLWithRedirect instead which returns both auth URL and redirect URL
func (*Manager) GetAuthURLWithRedirect ¶
func (m *Manager) GetAuthURLWithRedirect(providerName, state, hostOrBaseURL, authPathPrefix string) (string, string, error)
GetAuthURLWithRedirect generates an authorization URL and returns both the auth URL and redirect URL. This is useful for dynamic port mapping (e.g., Docker environments). The hostOrBaseURL parameter can be:
- A full base URL (e.g., "http://localhost:4182")
- A host with port (e.g., "localhost:4182")
- Just a host (e.g., "example.com")
Returns: (authURL, redirectURL, error)
func (*Manager) GetProvider ¶
GetProvider retrieves a provider by name
func (*Manager) GetProviders ¶
GetProviders returns all providers
type MicrosoftProvider ¶
type MicrosoftProvider struct {
// contains filtered or unexported fields
}
MicrosoftProvider is the OAuth2 provider for Microsoft (Azure AD)
func NewMicrosoftProvider ¶
func NewMicrosoftProvider(clientID, clientSecret, redirectURL string, scopes []string, resetScopes bool) *MicrosoftProvider
NewMicrosoftProvider creates a new Microsoft OAuth2 provider
func (*MicrosoftProvider) Config ¶
func (p *MicrosoftProvider) Config() *oauth2.Config
Config returns the OAuth2 config
func (*MicrosoftProvider) GetUserEmail ¶
GetUserEmail retrieves the user's email from Microsoft Graph API (deprecated, use GetUserInfo)
func (*MicrosoftProvider) GetUserInfo ¶
func (p *MicrosoftProvider) GetUserInfo(ctx context.Context, token *oauth2.Token) (*UserInfo, error)
GetUserInfo retrieves the user's information from Microsoft Graph API
func (*MicrosoftProvider) Name ¶
func (p *MicrosoftProvider) Name() string
Name returns the provider name
type Provider ¶
type Provider interface {
Name() string
Config() *oauth2.Config
GetUserInfo(ctx context.Context, token *oauth2.Token) (*UserInfo, error)
// Deprecated: Use GetUserInfo instead
GetUserEmail(ctx context.Context, token *oauth2.Token) (string, error)
}
Provider is an interface for OAuth2 providers