66
77use SimpleSAML \Module \oidc \Helpers ;
88use SimpleSAML \Module \oidc \ModuleConfig ;
9- use SimpleSAML \Module \oidc \Repositories \ClientRepository ;
109use SimpleSAML \Module \oidc \Server \Exceptions \OidcServerException ;
1110use SimpleSAML \Module \oidc \Services \LoggerService ;
1211use SimpleSAML \Module \oidc \Services \OpMetadataService ;
1615use SimpleSAML \OpenID \Codebooks \ClientRegistrationTypesEnum ;
1716use SimpleSAML \OpenID \Codebooks \ContentTypesEnum ;
1817use SimpleSAML \OpenID \Codebooks \EntityTypesEnum ;
19- use SimpleSAML \OpenID \Codebooks \ErrorsEnum ;
2018use SimpleSAML \OpenID \Codebooks \HttpHeadersEnum ;
2119use SimpleSAML \OpenID \Federation ;
2220use SimpleSAML \OpenID \Jwks ;
23- use Symfony \Component \HttpFoundation \Request ;
2421use Symfony \Component \HttpFoundation \Response ;
2522
2623class EntityStatementController
@@ -35,7 +32,6 @@ public function __construct(
3532 protected readonly ModuleConfig $ moduleConfig ,
3633 protected readonly Jwks $ jwks ,
3734 protected readonly OpMetadataService $ opMetadataService ,
38- protected readonly ClientRepository $ clientRepository ,
3935 protected readonly Helpers $ helpers ,
4036 protected readonly Routes $ routes ,
4137 protected readonly Federation $ federation ,
@@ -224,113 +220,6 @@ public function configuration(): Response
224220 return $ this ->prepareEntityStatementResponse ($ entityConfigurationToken );
225221 }
226222
227- public function fetch (Request $ request ): Response
228- {
229- $ subject = $ request ->query ->getString (ClaimsEnum::Sub->value );
230-
231- if (empty ($ subject )) {
232- return $ this ->routes ->newJsonErrorResponse (
233- ErrorsEnum::InvalidRequest->value ,
234- sprintf ('Missing parameter %s ' , ClaimsEnum::Sub->value ),
235- 400 ,
236- );
237- }
238-
239- /** @var non-empty-string $subject */
240-
241- $ cachedSubordinateStatement = $ this ->federationCache ?->get(
242- null ,
243- self ::KEY_RP_SUBORDINATE_ENTITY_STATEMENT ,
244- $ subject ,
245- );
246-
247- if (!is_null ($ cachedSubordinateStatement )) {
248- return $ this ->prepareEntityStatementResponse ((string )$ cachedSubordinateStatement );
249- }
250-
251- $ client = $ this ->clientRepository ->findFederatedByEntityIdentifier ($ subject );
252- if (empty ($ client )) {
253- return $ this ->routes ->newJsonErrorResponse (
254- ErrorsEnum::NotFound->value ,
255- sprintf ('Subject not found (%s) ' , $ subject ),
256- 404 ,
257- );
258- }
259-
260- $ jwks = $ client ->getFederationJwks ();
261- if (empty ($ jwks )) {
262- return $ this ->routes ->newJsonErrorResponse (
263- ErrorsEnum::InvalidClient->value ,
264- sprintf ('Subject does not contain JWKS claim (%s) ' , $ subject ),
265- 401 ,
266- );
267- }
268-
269- $ currentTimestamp = $ this ->helpers ->dateTime ()->getUtc ()->getTimestamp ();
270-
271- $ payload = [
272- ClaimsEnum::Iss->value => $ this ->moduleConfig ->getIssuer (),
273- ClaimsEnum::Iat->value => $ currentTimestamp ,
274- ClaimsEnum::Jti->value => $ this ->helpers ->random ()->getIdentifier (),
275-
276- ClaimsEnum::Sub->value => $ subject ,
277- ClaimsEnum::Exp->value => $ this ->helpers ->dateTime ()->getUtc ()->add (
278- $ this ->moduleConfig ->getFederationEntityStatementDuration (),
279- )->getTimestamp (),
280- ClaimsEnum::Jwks->value => $ jwks ,
281- ClaimsEnum::Metadata->value => [
282- EntityTypesEnum::OpenIdRelyingParty->value => [
283- ClaimsEnum::ClientName->value => $ client ->getName (),
284- ClaimsEnum::ClientId->value => $ client ->getIdentifier (),
285- ClaimsEnum::RedirectUris->value => $ client ->getRedirectUris (),
286- ClaimsEnum::Scope->value => implode (' ' , $ client ->getScopes ()),
287- ClaimsEnum::ClientRegistrationTypes->value => $ client ->getClientRegistrationTypes (),
288- // Optional claims...
289- ...(array_filter (
290- [
291- ClaimsEnum::BackChannelLogoutUri->value => $ client ->getBackChannelLogoutUri (),
292- ClaimsEnum::PostLogoutRedirectUris->value => $ client ->getPostLogoutRedirectUri (),
293- ],
294- )),
295- // TODO v7 mivanci Continue
296- // https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
297- // https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtml#client-metadata
298- ],
299- ],
300- ];
301-
302- // TODO v7 mivanci Continue
303- // Note: claims which can be present in subordinate statements:
304- // * metadata_policy
305- // * constraints
306- // * metadata_policy_crit
307-
308- $ signingKeyPair = $ this ->moduleConfig
309- ->getFederationSignatureKeyPairBag ()
310- ->getFirstOrFail ();
311-
312-
313- $ header = [
314- ClaimsEnum::Kid->value => $ signingKeyPair ->getKeyPair ()->getKeyId (),
315- ];
316-
317- $ subordinateStatementToken = $ this ->federation ->entityStatementFactory ()->fromData (
318- $ signingKeyPair ->getKeyPair ()->getPrivateKey (),
319- $ signingKeyPair ->getSignatureAlgorithm (),
320- $ payload ,
321- $ header ,
322- )->getToken ();
323-
324- $ this ->federationCache ?->set(
325- $ subordinateStatementToken ,
326- $ this ->moduleConfig ->getFederationEntityStatementCacheDurationForProduced (),
327- self ::KEY_RP_SUBORDINATE_ENTITY_STATEMENT ,
328- $ subject ,
329- );
330-
331- return $ this ->prepareEntityStatementResponse ($ subordinateStatementToken );
332- }
333-
334223 protected function prepareEntityStatementResponse (string $ entityStatementToken ): Response
335224 {
336225 return $ this ->routes ->newResponse (
0 commit comments