oidc

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedDiscovery

type CachedDiscovery struct {
	Discovery *OIDCDiscovery
	ExpiresAt time.Time
}

CachedDiscovery represents cached OIDC discovery document with expiration

type CachedJWKS

type CachedJWKS struct {
	JWKS      *JWKS
	ExpiresAt time.Time
}

CachedJWKS represents cached JWKS with expiration

type JWK

type JWK struct {
	Kty string `json:"kty"`           // Key Type
	Use string `json:"use,omitempty"` // Public Key Use
	Kid string `json:"kid,omitempty"` // Key ID
	Alg string `json:"alg,omitempty"` // Algorithm
	N   string `json:"n,omitempty"`   // RSA modulus
	E   string `json:"e,omitempty"`   // RSA exponent
	X   string `json:"x,omitempty"`   // EC/OKP x coordinate
	Y   string `json:"y,omitempty"`   // EC y coordinate
	Crv string `json:"crv,omitempty"` // EC curve / OKP subtype
}

JWK represents a JSON Web Key

type JWKS

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

JWKS represents a JSON Web Key Set

type OIDCDiscovery

type OIDCDiscovery struct {
	Issuer                            string   `json:"issuer"`
	AuthorizationEndpoint             string   `json:"authorization_endpoint"`
	TokenEndpoint                     string   `json:"token_endpoint"`
	UserinfoEndpoint                  string   `json:"userinfo_endpoint,omitempty"`
	JwksURI                           string   `json:"jwks_uri"`
	RegistrationEndpoint              string   `json:"registration_endpoint,omitempty"`
	ScopesSupported                   []string `json:"scopes_supported,omitempty"`
	ResponseTypesSupported            []string `json:"response_types_supported"`
	ResponseModesSupported            []string `json:"response_modes_supported,omitempty"`
	GrantTypesSupported               []string `json:"grant_types_supported,omitempty"`
	SubjectTypesSupported             []string `json:"subject_types_supported"`
	IDTokenSigningAlgValuesSupported  []string `json:"id_token_signing_alg_values_supported"`
	TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
	ClaimsSupported                   []string `json:"claims_supported,omitempty"`
	CodeChallengeMethodsSupported     []string `json:"code_challenge_methods_supported,omitempty"`
	RevocationEndpoint                string   `json:"revocation_endpoint,omitempty"`
	EndSessionEndpoint                string   `json:"end_session_endpoint,omitempty"`
}

OIDCDiscovery represents OIDC Provider Configuration Reference: https://openid.net/specs/openid-connect-discovery-1_0.html

type OIDCTokenResponse

type OIDCTokenResponse 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"`
	Scope        string `json:"scope,omitempty"`
}

OIDCTokenResponse represents the response from token endpoint

type OIDCUserInfo

type OIDCUserInfo struct {
	Sub               string `json:"sub"`
	Name              string `json:"name,omitempty"`
	GivenName         string `json:"given_name,omitempty"`
	FamilyName        string `json:"family_name,omitempty"`
	Email             string `json:"email,omitempty"`
	EmailVerified     bool   `json:"email_verified,omitempty"`
	Picture           string `json:"picture,omitempty"`
	PreferredUsername string `json:"preferred_username,omitempty"`
}

OIDCUserInfo represents user information from userinfo endpoint

type PKCEChallenge

type PKCEChallenge struct {
	CodeVerifier  string
	CodeChallenge string
	Method        string
}

PKCEChallenge represents PKCE challenge data

type Service

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

Service handles OIDC operations

func NewService

func NewService() *Service

NewService creates a new OIDC service

func (*Service) ExchangeCodeForTokens

func (s *Service) ExchangeCodeForTokens(ctx context.Context, tokenEndpoint, clientID, clientSecret, code, redirectURI, codeVerifier string) (*OIDCTokenResponse, error)

ExchangeCodeForTokens exchanges authorization code for tokens

func (*Service) FetchDiscovery

func (s *Service) FetchDiscovery(ctx context.Context, issuerURL string) (*OIDCDiscovery, error)

FetchDiscovery fetches OIDC Provider Configuration with caching issuerURL should be the base issuer URL (e.g., "https://accounts.google.com")

func (*Service) FetchJWKS

func (s *Service) FetchJWKS(ctx context.Context, jwksURL string) (*JWKS, error)

FetchJWKS fetches JWKS from the given URL with caching

func (*Service) GeneratePKCEChallenge

func (s *Service) GeneratePKCEChallenge() (*PKCEChallenge, error)

GeneratePKCEChallenge generates a PKCE challenge for OAuth2 flow

func (*Service) GetPublicKeyFromJWK

func (s *Service) GetPublicKeyFromJWK(jwk *JWK) (interface{}, error)

GetPublicKeyFromJWK converts a JWK to a public key for JWT verification

func (*Service) GetUserInfo

func (s *Service) GetUserInfo(ctx context.Context, userinfoEndpoint, accessToken string) (*OIDCUserInfo, error)

GetUserInfo fetches user information from the userinfo endpoint

func (*Service) RefreshTokens

func (s *Service) RefreshTokens(ctx context.Context, tokenEndpoint, clientID, clientSecret, refreshToken string) (*OIDCTokenResponse, error)

RefreshTokens refreshes access tokens using a refresh token

func (*Service) ValidateIDToken

func (s *Service) ValidateIDToken(ctx context.Context, tokenString, jwksURL, issuer, clientID, nonce string) (*jwt.MapClaims, error)

ValidateIDToken validates an OIDC ID token using JWKS for signature verification

func (*Service) ValidateIDTokenWithJWKS

func (s *Service) ValidateIDTokenWithJWKS(ctx context.Context, idToken, jwksURL, expectedIssuer, expectedAudience, expectedNonce string) (*jwt.MapClaims, error)

ValidateIDTokenWithJWKS validates an ID token using remote JWKS

Jump to

Keyboard shortcuts

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