oidc

package
v0.0.0-...-dac86b4 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateState

func GenerateState() (string, error)

GenerateState produces a cryptographically random state parameter.

Types

type Claims

type Claims struct {
	Subject       string   `json:"sub"`
	Email         string   `json:"email"`
	EmailVerified bool     `json:"email_verified"`
	Name          string   `json:"name"`
	Groups        []string `json:"groups,omitempty"`
	Issuer        string   `json:"iss"`
	Audience      string   `json:"aud"`
	ExpiresAt     int64    `json:"exp"`
	IssuedAt      int64    `json:"iat"`
}

Claims represents the standard claims extracted from an ID token.

func ParseIDTokenUnverified

func ParseIDTokenUnverified(idToken string) (*Claims, error)

ParseIDTokenUnverified extracts claims from an ID token without cryptographic verification. Use this only when you have already validated the token via the token endpoint response.

type Config

type Config struct {
	Issuer       string   `json:"issuer" yaml:"issuer"`
	ClientID     string   `json:"client_id" yaml:"client_id"`
	ClientSecret string   `json:"client_secret" yaml:"client_secret"`
	RedirectURI  string   `json:"redirect_uri" yaml:"redirect_uri"`
	Scopes       []string `json:"scopes" yaml:"scopes"`
}

Config holds OIDC provider configuration.

func (Config) Validate

func (c Config) Validate() error

Validate checks that required configuration fields are set.

type DiscoveryDocument

type DiscoveryDocument struct {
	Issuer                string   `json:"issuer"`
	AuthorizationEndpoint string   `json:"authorization_endpoint"`
	TokenEndpoint         string   `json:"token_endpoint"`
	UserInfoEndpoint      string   `json:"userinfo_endpoint"`
	JWKSURI               string   `json:"jwks_uri"`
	ScopesSupported       []string `json:"scopes_supported"`
}

DiscoveryDocument represents the OpenID Connect discovery response.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface for making HTTP requests (allows testing).

type Provider

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

Provider handles OIDC authentication flows.

func NewProvider

func NewProvider(cfg Config, client HTTPClient) (*Provider, error)

NewProvider creates a new OIDC provider with the given configuration.

func (*Provider) AuthorizationURL

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

AuthorizationURL builds the URL to redirect users for authentication.

func (*Provider) CallbackHandler

func (p *Provider) CallbackHandler(onSuccess func(w http.ResponseWriter, r *http.Request, claims *Claims, tokens *TokenResponse)) http.HandlerFunc

CallbackHandler returns an HTTP handler that processes the OIDC authorization code callback. On success it calls onSuccess with the extracted claims.

func (*Provider) Config

func (p *Provider) Config() Config

Config returns the provider's configuration.

func (*Provider) Discover

func (p *Provider) Discover(ctx context.Context) (*DiscoveryDocument, error)

Discover fetches the OIDC discovery document from the issuer.

func (*Provider) ExchangeCode

func (p *Provider) ExchangeCode(ctx context.Context, code string) (*TokenResponse, error)

ExchangeCode exchanges an authorization code for tokens.

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token,omitempty"`
	IDToken      string `json:"id_token,omitempty"`
}

TokenResponse represents the response from the token endpoint.

Jump to

Keyboard shortcuts

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