oidc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProviderName is the auth method reported by the OIDC redirect provider.
	ProviderName = "oidc"

	// DefaultScopes is the envconfig default for CAESIUM_AUTH_OIDC_SCOPES.
	DefaultScopes = "openid profile email groups"

	// DefaultGroupsClaim is the envconfig default for CAESIUM_AUTH_OIDC_GROUPS_CLAIM.
	DefaultGroupsClaim = "groups"

	// DefaultRedirectPath is the Caesium callback path used when only a public
	// base URL is configured.
	DefaultRedirectPath = "/auth/sso/oidc/callback"

	DefaultStateCookieName = "caesium_oidc_state"
	DefaultStateTTL        = 10 * time.Minute
)

Variables

View Source
var (
	ErrAuthorizationFailed = errors.New("oidc authorization failed")
	ErrMissingCode         = errors.New("oidc callback missing code")
	ErrMissingIDToken      = errors.New("oidc token response missing id_token")
	ErrInvalidIDToken      = errors.New("invalid oidc id_token")
	ErrInvalidNonce        = errors.New("invalid oidc nonce")
	ErrInvalidGroupsClaim  = errors.New("invalid oidc groups claim")
)
View Source
var (
	ErrInvalidReturnTo = errors.New("invalid returnTo")
	ErrInvalidState    = errors.New("invalid oidc state")
)

Functions

func ParseScopes

func ParseScopes(raw string) []string

ParseScopes parses CAESIUM_AUTH_OIDC_SCOPES. Empty input returns the default OpenID Connect scopes.

Types

type Config

type Config struct {
	IssuerURL     string
	ClientID      string
	ClientSecret  string
	Scopes        []string
	GroupsClaim   string
	RedirectURL   string
	PublicBaseURL string

	StateCookieName string
	StateTTL        time.Duration
	CookieSecure    bool
	CookieSecret    []byte

	HTTPClient *http.Client
}

Config configures the OIDC redirect provider.

func ConfigFromEnv

func ConfigFromEnv(vars env.Environment) Config

ConfigFromEnv converts Caesium environment config into provider config. The caller still controls construction so startup can decide when OIDC is enabled.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the Caesium browser redirect authenticator for OIDC.

func New

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

New discovers the OIDC issuer and constructs an Authorization Code + PKCE redirect provider.

func (*Provider) Begin

func (p *Provider) Begin(w http.ResponseWriter, _ *http.Request, returnTo string) (string, error)

Begin creates the signed pre-login state cookie and returns the IdP authorization URL.

func (*Provider) ClearStateCookie

func (p *Provider) ClearStateCookie(w http.ResponseWriter, _ *http.Request)

ClearStateCookie expires the one-time pre-login state cookie.

func (*Provider) Complete

func (p *Provider) Complete(r *http.Request) (*authpkg.ExternalIdentity, error)

Complete validates the callback and returns the normalized external identity.

func (*Provider) CompleteWithReturnTo

func (p *Provider) CompleteWithReturnTo(r *http.Request) (*authpkg.ExternalIdentity, string, error)

CompleteWithReturnTo is the callback variant route handlers can use when they need the same-origin return destination stored during Begin.

func (*Provider) Name

func (p *Provider) Name() string

Name reports the provider id used by the shared SSO completion path.

Jump to

Keyboard shortcuts

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