oidc

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 21 Imported by: 0

Documentation

Overview

Package oidc implements the OpenID Connect protocol connector for enterprise SSO.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDiscoveryFailed  = errors.New("sso oidc: provider discovery failed")
	ErrTokenExchange    = errors.New("sso oidc: token exchange failed")
	ErrInvalidIDToken   = errors.New("sso oidc: invalid id_token")
	ErrSignatureInvalid = errors.New("sso oidc: id_token signature invalid")
	ErrIssuerMismatch   = errors.New("sso oidc: issuer mismatch")
	ErrAudienceMismatch = errors.New("sso oidc: audience mismatch")
	ErrNonceMismatch    = errors.New("sso oidc: nonce mismatch")
	ErrTokenExpired     = errors.New("sso oidc: token expired")
	ErrKeyNotFound      = errors.New("sso oidc: signing key not found in jwks")
)

Functions

func GenerateNonce

func GenerateNonce() string

GenerateNonce creates a secure random nonce string.

func GeneratePKCE

func GeneratePKCE() (verifier, challenge string, err error)

GeneratePKCE creates an RFC 7636 code verifier and S256 challenge.

Types

type Client

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

func NewClient

func NewClient(httpClient HTTPClient) *Client

func (*Client) BuildAuthURL

func (c *Client) BuildAuthURL(authEndpoint string, cfg *OIDCConfig, state, nonce, challenge string) string

BuildAuthURL constructs the provider authorization URL with PKCE and Nonce.

func (*Client) Discover

func (c *Client) Discover(ctx context.Context, issuer, discoveryURL string) (*DiscoveryDocument, error)

Discover fetches the OpenID Connect discovery document.

func (*Client) ExchangeCode

func (c *Client) ExchangeCode(ctx context.Context, tokenEndpoint string, cfg *OIDCConfig, code, verifier, redirectURI string) (*TokenResponse, error)

ExchangeCode exchanges an authorization code for tokens.

func (*Client) FetchJWKS

func (c *Client) FetchJWKS(ctx context.Context, jwksURI string) (*JWKS, error)

FetchJWKS gets provider JWKS with caching.

func (*Client) VerifyIDToken

func (c *Client) VerifyIDToken(rawToken string, jwks *JWKS, cfg *OIDCConfig, expectedNonce string, now time.Time) (*IDTokenClaims, error)

VerifyIDToken strictly verifies signature, issuer, audience, expiration, and nonce.

type DiscoveryDocument

type DiscoveryDocument struct {
	Issuer                string `json:"issuer"`
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	TokenEndpoint         string `json:"token_endpoint"`
	JWKSUri               string `json:"jwks_uri"`
	UserInfoEndpoint      string `json:"userinfo_endpoint,omitempty"`
}

type HTTPClient

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

HTTPClient abstracts outbound HTTP request execution.

type IDTokenClaims

type IDTokenClaims struct {
	Issuer    string         `json:"iss"`
	Subject   string         `json:"sub"`
	Audience  []string       `json:"aud"`
	ExpiresAt time.Time      `json:"exp"`
	IssuedAt  time.Time      `json:"iat"`
	Nonce     string         `json:"nonce"`
	Email     string         `json:"email"`
	Name      string         `json:"name"`
	Raw       map[string]any `json:"-"`
}

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Kid string `json:"kid"`
	Use string `json:"use"`
	Alg string `json:"alg"`
	N   string `json:"n"`
	E   string `json:"e"`
	Crv string `json:"crv"`
	X   string `json:"x"`
	Y   string `json:"y"`
}

type JWKS

type JWKS struct {
	Keys []JWK `json:"keys"`
}

type OIDCConfig

type OIDCConfig struct {
	Issuer          string   `json:"issuer"`
	ClientID        string   `json:"client_id"`
	ClientSecret    string   `json:"client_secret"`
	RedirectURI     string   `json:"redirect_uri"`
	Scopes          []string `json:"scopes"`
	DiscoveryURL    string   `json:"discovery_url,omitempty"`
	SkipIssuerCheck bool     `json:"skip_issuer_check,omitempty"`
}

OIDCConfig contains OpenID Connect specific parameters.

type TokenResponse

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

TokenResponse models the OIDC token endpoint response.

Jump to

Keyboard shortcuts

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