Documentation
¶
Overview ¶
Package oidc_provider - OAuth/OIDC provider integration with automatic user creation and linking.
Index ¶
- Constants
- func OidcFetchUserInfo(verifier *gooidc.IDTokenVerifier) func(context.Context, *oauth2.Token, string) (*UserInfo, error)
- type Config
- type Deps
- type Provider
- func New(ctx context.Context, cfg Config, deps Deps) *Provider
- func NewAppleProvider(ctx context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
- func NewGitHubProvider(_ context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
- func NewGoogleProvider(ctx context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
- type StateData
- type UserInfo
Constants ¶
const ( GoogleIssuer = "https://accounts.google.com" AppleIssuer = "https://appleid.apple.com" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string
// OAuth2 credentials
ClientID string
ClientSecret string
RedirectURL string
// Scopes to request (e.g. []string{"openid", "email", "profile"})
Scopes []string
// AuthCodeOptions are additional options passed to AuthCodeURL.
AuthCodeOptions []oauth2.AuthCodeOption
// LoginPath is where to redirect on auth errors.
LoginPath string
// SuccessPath is where to redirect after successful login.
SuccessPath string
IssuerUrl string
JwksUrl string
Endpoint oauth2.Endpoint
// FetchUserInfo extracts user identity from the token response.
// For OIDC providers, leave nil to use automatic ID token verification.
// For plain OAuth2 providers, set this to call the provider's userinfo API.
FetchUserInfo func(ctx context.Context, token *oauth2.Token, nonce string) (*UserInfo, error)
}
Config holds the configuration for an OAuth provider.
type Deps ¶
type Deps struct {
DB *sql.DB
Tokens dbi.Factory[tokens.Store[StateData]]
Users dbi.Factory[iam.UserStore]
OAuth dbi.Factory[iam.OAuthStore]
Provisioner provision.Provisioner
SessionMan *iam.SessionMan
}
Deps holds the dependencies injected by the application.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider handles OAuth authentication for a single identity provider.
func New ¶
New creates a new OAuth Provider. For OIDC providers (Issuer set, Endpoint nil), it performs OIDC discovery and sets up automatic ID token verification. For plain OAuth2 providers (Endpoint set), FetchUserInfo must be provided.
func NewAppleProvider ¶
func NewAppleProvider(ctx context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
NewAppleProvider creates a Provider configured for Sign in with Apple. The clientSecret should be a JWT signed with your Apple private key.
func NewGitHubProvider ¶
func NewGitHubProvider(_ context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
NewGitHubProvider creates a Provider configured for GitHub OAuth.
func NewGoogleProvider ¶
func NewGoogleProvider(ctx context.Context, clientID, clientSecret, redirectURL string, deps Deps) *Provider
NewGoogleProvider creates a Provider configured for Google Sign-In.
func (*Provider) BuildAuthUrl ¶
type StateData ¶
StateData holds the PKCE and nonce values for an in-progress OAuth flow.
Source Files
¶
- helpers.go
- presets.go
- provider.go
- state.go
- user_info.go