1313use SimpleSAML \Module \oidc \Services \LoggerService ;
1414use SimpleSAML \Module \oidc \Services \OpMetadataService ;
1515use SimpleSAML \Module \oidc \Utils \FederationCache ;
16+ use SimpleSAML \Module \oidc \Utils \FingerprintGenerator ;
1617use SimpleSAML \Module \oidc \Utils \Routes ;
18+ use SimpleSAML \OpenID \Algorithms \SignatureAlgorithmEnum ;
1719use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
1820use SimpleSAML \OpenID \Codebooks \ClientRegistrationTypesEnum ;
1921use SimpleSAML \OpenID \Codebooks \ContentTypesEnum ;
2224use SimpleSAML \OpenID \Codebooks \HttpHeadersEnum ;
2325use SimpleSAML \OpenID \Codebooks \JwtTypesEnum ;
2426use SimpleSAML \OpenID \Federation ;
27+ use SimpleSAML \OpenID \Jwk ;
2528use Symfony \Component \HttpFoundation \Request ;
2629use Symfony \Component \HttpFoundation \Response ;
2730
@@ -42,6 +45,7 @@ public function __construct(
4245 private readonly Helpers $ helpers ,
4346 private readonly Routes $ routes ,
4447 private readonly Federation $ federation ,
48+ private readonly Jwk $ jwk ,
4549 private readonly LoggerService $ loggerService ,
4650 private readonly ?FederationCache $ federationCache ,
4751 ) {
@@ -55,7 +59,6 @@ public function __construct(
5559 *
5660 * @return \Symfony\Component\HttpFoundation\Response
5761 * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException
58- * @throws \ReflectionException
5962 * @throws \SimpleSAML\OpenID\Exceptions\JwsException
6063 * @throws \Psr\SimpleCache\InvalidArgumentException
6164 */
@@ -71,59 +74,66 @@ public function configuration(): Response
7174 return $ this ->prepareEntityStatementResponse ((string )$ cachedEntityConfigurationToken );
7275 }
7376
74- $ builder = $ this ->jsonWebTokenBuilderService ->getFederationJwtBuilder ()
75- ->withHeader (ClaimsEnum::Typ->value , JwtTypesEnum::EntityStatementJwt->value )
76- ->relatedTo ($ this ->moduleConfig ->getIssuer ()) // This is entity configuration (statement about itself).
77- ->expiresAt (
78- $ this ->helpers ->dateTime ()->getUtc ()->add ($ this ->moduleConfig ->getFederationEntityStatementDuration ()),
79- )->withClaim (
80- ClaimsEnum::Jwks->value ,
81- ['keys ' => array_values ($ this ->jsonWebKeySetService ->federationKeys ()),],
82- )
83- ->withClaim (
84- ClaimsEnum::Metadata->value ,
85- [
86- EntityTypesEnum::FederationEntity->value => [
87- // Common https://openid.net/specs/openid-federation-1_0.html#name-common-metadata-parameters
88- ...(array_filter (
89- [
90- ClaimsEnum::OrganizationName->value => $ this ->moduleConfig ->getOrganizationName (),
91- ClaimsEnum::Contacts->value => $ this ->moduleConfig ->getContacts (),
92- ClaimsEnum::LogoUri->value => $ this ->moduleConfig ->getLogoUri (),
93- ClaimsEnum::PolicyUri->value => $ this ->moduleConfig ->getPolicyUri (),
94- ClaimsEnum::HomepageUri->value => $ this ->moduleConfig ->getHomepageUri (),
95- ],
96- )),
97- ClaimsEnum::FederationFetchEndpoint->value => $ this ->routes ->urlFederationFetch (),
98- ClaimsEnum::FederationListEndpoint->value => $ this ->routes ->urlFederationList (),
99- // TODO v7 mivanci Add when ready. Use ClaimsEnum for keys.
100- // https://openid.net/specs/openid-federation-1_0.html#name-federation-entity
101- //'federation_resolve_endpoint',
102- //'federation_trust_mark_status_endpoint',
103- //'federation_trust_mark_list_endpoint',
104- //'federation_trust_mark_endpoint',
105- //'federation_historical_keys_endpoint',
106- //'endpoint_auth_signing_alg_values_supported'
107- // Common https://openid.net/specs/openid-federation-1_0.html#name-common-metadata-parameters
108- //'signed_jwks_uri',
109- //'jwks_uri',
110- //'jwks',
111- ],
112- // OP metadata with additional federation related claims.
113- EntityTypesEnum::OpenIdProvider->value => [
114- ...$ this ->opMetadataService ->getMetadata (),
115- ClaimsEnum::ClientRegistrationTypesSupported->value => [
116- ClientRegistrationTypesEnum::Automatic->value ,
77+ $ currentTimestamp = $ this ->helpers ->dateTime ()->getUtc ()->getTimestamp ();
78+
79+ $ header = [
80+ ClaimsEnum::Kid->value => FingerprintGenerator::forFile (
81+ $ this ->moduleConfig ->getFederationCertPath (),
82+ ),
83+ ];
84+
85+ $ payload = [
86+ ClaimsEnum::Iss->value => $ this ->moduleConfig ->getIssuer (),
87+ ClaimsEnum::Iat->value => $ currentTimestamp ,
88+ ClaimsEnum::Jti->value => $ this ->helpers ->random ()->getIdentifier (),
89+ // This is entity configuration (statement about itself).
90+ ClaimsEnum::Sub->value => $ this ->moduleConfig ->getIssuer (),
91+ ClaimsEnum::Exp->value => $ this ->helpers ->dateTime ()->getUtc ()->add (
92+ $ this ->moduleConfig ->getFederationEntityStatementDuration (),
93+ )->getTimestamp (),
94+ ClaimsEnum::Jwks->value => ['keys ' => array_values ($ this ->jsonWebKeySetService ->federationKeys ()),],
95+ ClaimsEnum::Metadata->value => [
96+ EntityTypesEnum::FederationEntity->value => [
97+ // Common https://openid.net/specs/openid-federation-1_0.html#name-common-metadata-parameters
98+ ...(array_filter (
99+ [
100+ ClaimsEnum::OrganizationName->value => $ this ->moduleConfig ->getOrganizationName (),
101+ ClaimsEnum::Contacts->value => $ this ->moduleConfig ->getContacts (),
102+ ClaimsEnum::LogoUri->value => $ this ->moduleConfig ->getLogoUri (),
103+ ClaimsEnum::PolicyUri->value => $ this ->moduleConfig ->getPolicyUri (),
104+ ClaimsEnum::HomepageUri->value => $ this ->moduleConfig ->getHomepageUri (),
117105 ],
106+ )),
107+ ClaimsEnum::FederationFetchEndpoint->value => $ this ->routes ->urlFederationFetch (),
108+ ClaimsEnum::FederationListEndpoint->value => $ this ->routes ->urlFederationList (),
109+ // TODO v7 mivanci Add when ready. Use ClaimsEnum for keys.
110+ // https://openid.net/specs/openid-federation-1_0.html#name-federation-entity
111+ //'federation_resolve_endpoint',
112+ //'federation_trust_mark_status_endpoint',
113+ //'federation_trust_mark_list_endpoint',
114+ //'federation_trust_mark_endpoint',
115+ //'federation_historical_keys_endpoint',
116+ //'endpoint_auth_signing_alg_values_supported'
117+ // Common https://openid.net/specs/openid-federation-1_0.html#name-common-metadata-parameters
118+ //'signed_jwks_uri',
119+ //'jwks_uri',
120+ //'jwks',
121+ ],
122+ // OP metadata with additional federation related claims.
123+ EntityTypesEnum::OpenIdProvider->value => [
124+ ...$ this ->opMetadataService ->getMetadata (),
125+ ClaimsEnum::ClientRegistrationTypesSupported->value => [
126+ ClientRegistrationTypesEnum::Automatic->value ,
118127 ],
119128 ],
120- );
129+ ],
130+ ];
121131
122132 if (
123133 is_array ($ authorityHints = $ this ->moduleConfig ->getFederationAuthorityHints ()) &&
124134 (!empty ($ authorityHints ))
125135 ) {
126- $ builder = $ builder -> withClaim ( ClaimsEnum::AuthorityHints->value , $ authorityHints) ;
136+ $ payload [ ClaimsEnum::AuthorityHints->value ] = $ authorityHints ;
127137 }
128138
129139 $ trustMarks = [];
@@ -186,16 +196,23 @@ public function configuration(): Response
186196 }
187197
188198 if (!empty ($ trustMarks )) {
189- $ builder = $ builder -> withClaim ( ClaimsEnum::TrustMarks->value , $ trustMarks) ;
199+ $ payload [ ClaimsEnum::TrustMarks->value ] = $ trustMarks ;
190200 }
191201
192202 // TODO v7 mivanci Continue
193203 // Remaining claims, add if / when ready.
194204 // * crit
195205
196- $ jws = $ this ->jsonWebTokenBuilderService ->getSignedFederationJwt ($ builder );
197-
198- $ entityConfigurationToken = $ jws ->toString ();
206+ /** @psalm-suppress ArgumentTypeCoercion */
207+ $ entityConfigurationToken = $ this ->federation ->entityStatementFactory ()->fromData (
208+ $ this ->jwk ->jwkDecoratorFactory ()->fromPkcs1Or8KeyFile (
209+ $ this ->moduleConfig ->getFederationPrivateKeyPath (),
210+ ),
211+ SignatureAlgorithmEnum::from ($ this ->moduleConfig ->getFederationSigner ()->algorithmId ()),
212+ $ payload ,
213+ $ header ,
214+ )
215+ ->getToken ();
199216
200217 $ this ->federationCache ?->set(
201218 $ entityConfigurationToken ,
0 commit comments