Documentation
¶
Index ¶
- Constants
- Variables
- func AuthCodeURL(issuer string) string
- func AuthRevokeURL(issuer string) string
- func AuthorizationScopes(config OIDCConfiguration, scopes ...string) []string
- func AuthorizationURL(issuer string) string
- func ConfigURL(issuer string) string
- func ExtractIssuer(token string) (string, error)
- func ExtractKeyID(token string) (string, error)
- func IssueToken(key *rsa.PrivateKey, claims jwt.MapClaims) (string, error)
- func JWKSURL(issuer string) string
- func NewCodeChallenge(method string) (string, string, error)
- func OAuthAuthorizationScopes(config OAuthConfiguration, scopes ...string) []string
- func OAuthConfigURL(issuer string) string
- func PreferredCodeChallengeMethod(methods []string) string
- func PublicJWKSet(key *rsa.PrivateKey) (jwk.Set, error)
- func PublicJWKSetForKeys(activeKeyID string, keys map[string]*rsa.PrivateKey) (jwk.Set, error)
- func SignToken(key *rsa.PrivateKey, claims jwt.Claims) (string, error)
- func SignTokenWithKeyID(kid string, key *rsa.PrivateKey, claims jwt.Claims) (string, error)
- func UserInfoURL(issuer string) string
- func VerifySignedToken(key *rsa.PublicKey, token, issuer string) (map[string]any, error)
- func VerifyToken(ctx context.Context, token string) (map[string]any, error)
- type AuthorizationCodeFlow
- type BaseConfiguration
- type JSONWebKey
- type JSONWebKeySet
- type OAuthConfiguration
- type OIDCConfiguration
- type ProtectedResourceMetadata
- type UserInfo
Constants ¶
const ( ResponseTypeCode = "code" CodeChallengeMethodPlain = "plain" CodeChallengeMethodS256 = "S256" )
const ( GoogleIssuer = "https://accounts.google.com" ConfigPath = ".well-known/openid-configuration" OAuthConfigPath = ".well-known/oauth-authorization-server" ProtectedResourcePath = ".well-known/oauth-protected-resource" JWKSPath = ".well-known/jwks.json" AuthorizationPath = "auth/authorize" AuthCodePath = "auth/code" AuthRevokePath = "auth/revoke" UserInfoPath = "auth/userinfo" SigningAlgorithm = "RS256" )
const ( ScopeOpenID = "openid" ScopeEmail = "email" ScopeProfile = "profile" )
Variables ¶
var DefaultOIDCAuthorizationScopes = []string{ScopeOpenID, ScopeEmail, ScopeProfile}
Functions ¶
func AuthCodeURL ¶
AuthCodeURL returns the local authorization-code exchange URL for an issuer.
func AuthRevokeURL ¶
AuthRevokeURL returns the local token revocation URL for an issuer.
func AuthorizationScopes ¶
func AuthorizationScopes(config OIDCConfiguration, scopes ...string) []string
AuthorizationScopes returns caller-supplied scopes, or preferred default OIDC scopes filtered to those advertised by discovery when present.
func AuthorizationURL ¶
AuthorizationURL returns the authorization endpoint URL for an issuer.
func ExtractIssuer ¶
ExtractIssuer returns the iss claim from a JWT payload without verifying the signature.
func ExtractKeyID ¶
ExtractKeyID returns the kid header from a JWT payload without verifying the signature.
func IssueToken ¶
IssueToken applies standard OIDC claim defaults and serializes the claims into a JWT.
func NewCodeChallenge ¶
NewCodeChallenge generates a code verifier and derived code challenge using the requested PKCE method.
func OAuthAuthorizationScopes ¶
func OAuthAuthorizationScopes(config OAuthConfiguration, scopes ...string) []string
OAuthAuthorizationScopes returns caller-supplied scopes, or advertised OAuth scopes when present. OAuth metadata has no implicit openid/profile default.
func OAuthConfigURL ¶
OAuthConfigURL returns the OAuth authorization server metadata URL for an issuer.
func PreferredCodeChallengeMethod ¶
PreferredCodeChallengeMethod chooses the strongest supported PKCE method.
func PublicJWKSet ¶
func PublicJWKSet(key *rsa.PrivateKey) (jwk.Set, error)
PublicJWKSet returns a JWKS document containing the public signing key for the supplied RSA private key without assigning a kid.
func PublicJWKSetForKeys ¶
PublicJWKSetForKeys returns a JWKS document containing the supplied public signing keys. When activeKeyID is present, it is added first.
func SignToken ¶
SignToken serializes claims into a JWT signed with the supplied RSA private key without setting a kid header. If key is nil, it returns an unsecured JWT using the "none" algorithm.
func SignTokenWithKeyID ¶
SignTokenWithKeyID serializes claims into a JWT signed with the supplied RSA private key and uses kid for the JWT kid header.
func UserInfoURL ¶
UserInfoURL returns the userinfo URL for an issuer.
func VerifySignedToken ¶
VerifySignedToken verifies a locally signed JWT with the supplied RSA public key and optionally checks the expected issuer.
Types ¶
type AuthorizationCodeFlow ¶
type AuthorizationCodeFlow struct {
Provider string `json:"provider,omitempty"`
Issuer string `json:"issuer,omitempty"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
AuthorizationURL string `json:"authorization_url"`
TokenEndpoint string `json:"token_endpoint,omitempty"`
TokenEndpointAuthMethods []string `json:"-"`
ClientID string `json:"client_id"`
RedirectURL string `json:"redirect_url"`
ResponseType string `json:"response_type"`
Scopes []string `json:"scopes,omitempty"`
State string `json:"state"`
Nonce string `json:"nonce,omitempty"`
CodeChallenge string `json:"code_challenge,omitempty"`
CodeChallengeMethod string `json:"code_challenge_method,omitempty"`
CodeVerifier string `json:"code_verifier,omitempty"`
}
AuthorizationCodeFlow contains the generated state required to start an interactive OAuth2/OIDC authorization code flow with optional PKCE.
func NewAuthorizationCodeFlow ¶
func NewAuthorizationCodeFlow(config BaseConfiguration, clientID, redirectURL string, scopes ...string) (*AuthorizationCodeFlow, error)
NewAuthorizationCodeFlow generates state and PKCE data needed to begin an interactive OAuth2/OIDC authorization code flow using the supplied discovery document. A nonce is added only for OIDC-capable configurations. clientID may be empty for provider-routed server-side exchanges where the server holds the upstream client credentials.
func (AuthorizationCodeFlow) URL ¶
func (flow AuthorizationCodeFlow) URL() (string, error)
URL returns the authorization URL for the flow.
func (*AuthorizationCodeFlow) ValidateCallback ¶
func (flow *AuthorizationCodeFlow) ValidateCallback(code, state string) (string, error)
ValidateCallback validates the authorization callback code and state against the flow state and returns the authorization code.
type BaseConfiguration ¶
type BaseConfiguration struct {
Issuer string `` /* 132-byte string literal not displayed */
AuthorizationEndpoint string `` /* 168-byte string literal not displayed */
TokenEndpoint string `` /* 169-byte string literal not displayed */
RegistrationEndpoint string `json:"registration_endpoint,omitempty" jsonschema:"Dynamic client registration endpoint, when supported." format:"uri"`
RevocationEndpoint string `` /* 180-byte string literal not displayed */
ResponseTypes []string `json:"response_types_supported,omitempty" jsonschema:"OAuth and OIDC response types supported by the authorization endpoint."`
GrantTypesSupported []string `json:"grant_types_supported,omitempty" jsonschema:"OAuth grant types supported by the token endpoint."`
ScopesSupported []string `json:"scopes_supported,omitempty" jsonschema:"Scopes that clients may request during authorization."`
CodeChallengeMethods []string `` /* 130-byte string literal not displayed */
TokenEndpointAuthMethods []string `json:"-"`
NonceSupported bool `json:"-"`
}
BaseConfiguration contains the fields shared by OIDC and OAuth authorization server metadata documents.
type JSONWebKey ¶
type JSONWebKey struct {
Algorithm string `json:"alg" jsonschema:"Signing algorithm associated with this key." example:"RS256"`
Exponent string `json:"e" jsonschema:"Base64url-encoded RSA public exponent." example:"AQAB"`
KeyID string `json:"kid,omitempty" jsonschema:"Key identifier used in JWT headers to select this key." example:"main"`
KeyType string `json:"kty" jsonschema:"Cryptographic key type." example:"RSA"`
Modulus string `` /* 412-byte string literal not displayed */
Use string `json:"use,omitempty" jsonschema:"Intended use of the key." example:"sig"`
}
JSONWebKey represents a public RSA signing key published in the JWKS document for locally issued tokens.
type JSONWebKeySet ¶
type JSONWebKeySet struct {
Keys []JSONWebKey `json:"keys" jsonschema:"Public signing keys published by this issuer for JWT verification."`
}
JSONWebKeySet is the public JWKS document returned for locally issued tokens.
type OAuthConfiguration ¶
type OAuthConfiguration struct {
BaseConfiguration
ResponseModesSupported []string `json:"response_modes_supported,omitempty"`
TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
}
OAuthConfiguration represents OAuth 2.0 Authorization Server Metadata.
type OIDCConfiguration ¶
type OIDCConfiguration struct {
BaseConfiguration
UserInfoEndpoint string `` /* 186-byte string literal not displayed */
JwksURI string `` /* 158-byte string literal not displayed */
SigningAlgorithms []string `json:"id_token_signing_alg_values_supported" jsonschema:"Signing algorithms used for locally issued ID and access tokens."`
SubjectTypes []string `json:"subject_types_supported" jsonschema:"OIDC subject identifier types supported by this issuer."`
ClaimsSupported []string `json:"claims_supported" jsonschema:"Claims that may appear in locally issued tokens and userinfo responses."`
TokenEndpointAuthMethodsSupported []string `` /* 146-byte string literal not displayed */
}
OIDCConfiguration represents the OpenID Connect discovery document.
type ProtectedResourceMetadata ¶
type ProtectedResourceMetadata struct {
Resource string `` /* 139-byte string literal not displayed */
AuthorizationServers []string `json:"authorization_servers,omitempty" jsonschema:"Authorization servers that issue bearer tokens accepted by this resource."`
ScopesSupported []string `json:"scopes_supported,omitempty" jsonschema:"Scopes that may be used when requesting access to this resource."`
BearerMethodsSupported []string `json:"bearer_methods_supported,omitempty" jsonschema:"Bearer token transport methods accepted by this resource."`
ResourceDocumentation string `` /* 127-byte string literal not displayed */
ResourceName string `json:"resource_name,omitempty" jsonschema:"Display name for this protected resource." example:"go-auth"`
}
ProtectedResourceMetadata describes this server as an OAuth protected resource.
func (ProtectedResourceMetadata) String ¶
func (c ProtectedResourceMetadata) String() string