oidc_provider

package module
v0.0.0-...-bd7611f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package oidc_provider - OAuth/OIDC provider integration with automatic user creation and linking.

Index

Constants

View Source
const (
	GoogleIssuer = "https://accounts.google.com"
	AppleIssuer  = "https://appleid.apple.com"
)

Variables

This section is empty.

Functions

func OidcFetchUserInfo

func OidcFetchUserInfo(verifier *gooidc.IDTokenVerifier) func(context.Context, *oauth2.Token, string) (*UserInfo, error)

OidcFetchUserInfo returns a FetchUserInfo function that verifies an OIDC ID token.

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

func New(ctx context.Context, cfg Config, deps Deps) *Provider

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

func (p *Provider) BuildAuthUrl(ctx context.Context) (string, error)

func (*Provider) HandleCallback

func (p *Provider) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*Provider) HandleLogin

func (p *Provider) HandleLogin(w http.ResponseWriter, r *http.Request)

type StateData

type StateData struct {
	CodeVerifier string
	Nonce        string
}

StateData holds the PKCE and nonce values for an in-progress OAuth flow.

type UserInfo

type UserInfo struct {
	Subject       string
	Email         string
	Name          string
	EmailVerified bool
}

UserInfo holds the identity information extracted from a provider.

Source Files

  • helpers.go
  • presets.go
  • provider.go
  • state.go
  • user_info.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL