idp

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package idp is a thin generic OIDC RP — authlet's AS uses it to forward user authentication to an upstream issuer (Google, another authlet, etc).

Index

Constants

This section is empty.

Variables

View Source
var ErrNoUser = errors.New("idp: no matching user")

ErrNoUser indicates that the upstream claims did not resolve to a known internal user.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Issuer        string `json:"iss"`
	Subject       string `json:"sub"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Name          string `json:"name"`
	Picture       string `json:"picture"`
	Raw           map[string]any
}

Claims is the subset of OIDC ID token claims authlet cares about.

type OIDCProvider

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

OIDCProvider is a configured upstream OIDC issuer. It pairs a verifier for inbound ID tokens with an oauth2 config used to drive the authorization code flow.

func NewForTest

func NewForTest(issuerURL string) *OIDCProvider

NewForTest is a test-only helper that constructs an OIDCProvider with stub-but-non-nil internals so it satisfies Configured() without doing network discovery. Use from external test packages only.

func NewOIDC

func NewOIDC(ctx context.Context, issuerURL, clientID, clientSecret, redirectURL string, scopes []string) (*OIDCProvider, error)

NewOIDC discovers the issuer's metadata and returns a configured provider.

func (*OIDCProvider) AuthURL

func (p *OIDCProvider) AuthURL(state string) string

AuthURL returns the upstream authorize URL for the given state.

func (*OIDCProvider) Configured

func (p *OIDCProvider) Configured() bool

Configured reports whether the provider was constructed via NewOIDC. A zero-valued *OIDCProvider is not configured and will panic if used, so callers (notably as.Config.validate) check this rather than just a nil pointer.

func (*OIDCProvider) Exchange

func (p *OIDCProvider) Exchange(ctx context.Context, code string) (Claims, error)

Exchange exchanges an upstream authorization code for an ID token and returns the parsed claims.

func (*OIDCProvider) Issuer

func (p *OIDCProvider) Issuer() string

Issuer returns the upstream issuer URL this provider was configured with.

type UserResolver

type UserResolver interface {
	Resolve(ctx context.Context, c Claims) (userID string, err error)
}

UserResolver maps upstream OIDC claims to an internal user ID. Apps implement this against their own user table.

type UserResolverFunc

type UserResolverFunc func(ctx context.Context, c Claims) (string, error)

UserResolverFunc is a function adapter that lets a plain function satisfy the UserResolver interface.

func (UserResolverFunc) Resolve

func (f UserResolverFunc) Resolve(ctx context.Context, c Claims) (string, error)

Resolve calls f(ctx, c).

Jump to

Keyboard shortcuts

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