Files
probo/pkg/iam/oauth2/metadata.go
Ludovic Vielle c93932f026 Introduce oauth2scope registry with freeze lifecycle
Replace pkg/iam/scopeset with pkg/iam/oauth2scope.Registry, a shared
OAuth2 scope→action registry used by the authorizer, OAuth2 service,
and Connect API. Registration stays open until probod calls Freeze();
read paths (RegisteredScopes, Allows, ValidateScopes) panic before
that.

Drop the leaky APIScopes surface and AllowedAPIScopes on manual
access-token creation in favor of registry.ValidateScopes. Metadata,
protected-resource metadata, and CIMD scope lists are built from
RegisteredScopes() via helpers in pkg/iam/oauth2/scopes.go. Expose
oauth2ScopesSupported as an OAuth2Scope GraphQL scalar.

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
2026-06-22 11:22:19 +02:00

123 lines
6.5 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package oauth2
import (
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/uri"
)
type (
// ServerMetadata represents the OpenID Connect Discovery 1.0 / RFC 8414
// authorization server metadata document.
ServerMetadata struct {
Issuer uri.URI `json:"issuer"`
AuthorizationEndpoint uri.URI `json:"authorization_endpoint"`
TokenEndpoint uri.URI `json:"token_endpoint"`
UserinfoEndpoint uri.URI `json:"userinfo_endpoint"`
JwksURI uri.URI `json:"jwks_uri"`
RegistrationEndpoint uri.URI `json:"registration_endpoint"`
IntrospectionEndpoint uri.URI `json:"introspection_endpoint"`
RevocationEndpoint uri.URI `json:"revocation_endpoint"`
DeviceAuthorizationEndpoint uri.URI `json:"device_authorization_endpoint"`
ScopesSupported []coredata.OAuth2Scope `json:"scopes_supported"`
ProtectedResources []uri.URI `json:"protected_resources,omitempty"`
ResponseTypesSupported []coredata.OAuth2ResponseType `json:"response_types_supported"`
GrantTypesSupported []coredata.OAuth2GrantType `json:"grant_types_supported"`
TokenEndpointAuthMethodsSupported []coredata.OAuth2ClientTokenEndpointAuthMethod `json:"token_endpoint_auth_methods_supported"`
RevocationEndpointAuthMethodsSupported []coredata.OAuth2ClientTokenEndpointAuthMethod `json:"revocation_endpoint_auth_methods_supported"`
IntrospectionEndpointAuthMethodsSupported []coredata.OAuth2ClientTokenEndpointAuthMethod `json:"introspection_endpoint_auth_methods_supported"`
SubjectTypesSupported []coredata.OAuth2SubjectType `json:"subject_types_supported"`
IDTokenSigningAlgValuesSupported []coredata.OAuth2SigningAlgorithm `json:"id_token_signing_alg_values_supported"`
CodeChallengeMethodsSupported []coredata.OAuth2CodeChallengeMethod `json:"code_challenge_methods_supported"`
ClaimsSupported []coredata.OAuth2Claim `json:"claims_supported"`
ClientIDMetadataDocumentSupported bool `json:"client_id_metadata_document_supported"`
}
// Endpoints holds the endpoint URLs for the OIDC discovery document.
Endpoints struct {
Authorization uri.URI
Token uri.URI
Userinfo uri.URI
JWKS uri.URI
Registration uri.URI
Introspection uri.URI
Revocation uri.URI
DeviceAuthorization uri.URI
}
)
func NewMetadata(issuer uri.URI, endpoints Endpoints, registeredScopes []coredata.OAuth2Scope) *ServerMetadata {
return &ServerMetadata{
Issuer: issuer,
AuthorizationEndpoint: endpoints.Authorization,
TokenEndpoint: endpoints.Token,
UserinfoEndpoint: endpoints.Userinfo,
JwksURI: endpoints.JWKS,
RegistrationEndpoint: endpoints.Registration,
IntrospectionEndpoint: endpoints.Introspection,
RevocationEndpoint: endpoints.Revocation,
DeviceAuthorizationEndpoint: endpoints.DeviceAuthorization,
ScopesSupported: authorizationServerScopes(registeredScopes),
ProtectedResources: []uri.URI{issuer},
ResponseTypesSupported: []coredata.OAuth2ResponseType{
coredata.OAuth2ResponseTypeCode,
},
GrantTypesSupported: []coredata.OAuth2GrantType{
coredata.OAuth2GrantTypeAuthorizationCode,
coredata.OAuth2GrantTypeRefreshToken,
coredata.OAuth2GrantTypeDeviceCode,
},
TokenEndpointAuthMethodsSupported: []coredata.OAuth2ClientTokenEndpointAuthMethod{
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretBasic,
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretPost,
coredata.OAuth2ClientTokenEndpointAuthMethodNone,
},
RevocationEndpointAuthMethodsSupported: []coredata.OAuth2ClientTokenEndpointAuthMethod{
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretBasic,
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretPost,
coredata.OAuth2ClientTokenEndpointAuthMethodNone,
},
IntrospectionEndpointAuthMethodsSupported: []coredata.OAuth2ClientTokenEndpointAuthMethod{
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretBasic,
coredata.OAuth2ClientTokenEndpointAuthMethodClientSecretPost,
coredata.OAuth2ClientTokenEndpointAuthMethodNone,
},
SubjectTypesSupported: []coredata.OAuth2SubjectType{
coredata.OAuth2SubjectTypePublic,
},
IDTokenSigningAlgValuesSupported: []coredata.OAuth2SigningAlgorithm{
coredata.OAuth2SigningAlgorithmRS256,
},
CodeChallengeMethodsSupported: []coredata.OAuth2CodeChallengeMethod{
coredata.OAuth2CodeChallengeMethodS256,
},
ClaimsSupported: []coredata.OAuth2Claim{
coredata.OAuth2ClaimIssuer,
coredata.OAuth2ClaimSubject,
coredata.OAuth2ClaimAudience,
coredata.OAuth2ClaimExpiration,
coredata.OAuth2ClaimIssuedAt,
coredata.OAuth2ClaimAuthTime,
coredata.OAuth2ClaimNonce,
coredata.OAuth2ClaimAtHash,
coredata.OAuth2ClaimEmail,
coredata.OAuth2ClaimEmailVerified,
coredata.OAuth2ClaimName,
},
ClientIDMetadataDocumentSupported: true,
}
}