1111use SimpleSAML \Module \oidc \Server \Exceptions \OidcServerException ;
1212use SimpleSAML \Module \oidc \Services \JsonWebKeySetService ;
1313use SimpleSAML \Module \oidc \Services \JsonWebTokenBuilderService ;
14+ use SimpleSAML \Module \oidc \Services \LoggerService ;
1415use SimpleSAML \Module \oidc \Services \OpMetadataService ;
1516use SimpleSAML \Module \oidc \Utils \FederationCache ;
1617use SimpleSAML \Module \oidc \Utils \Routes ;
@@ -42,6 +43,7 @@ public function __construct(
4243 private readonly Helpers $ helpers ,
4344 private readonly Routes $ routes ,
4445 private readonly Federation $ federation ,
46+ private readonly LoggerService $ loggerService ,
4547 private readonly ?FederationCache $ federationCache ,
4648 ) {
4749 if (!$ this ->moduleConfig ->getFederationEnabled ()) {
@@ -126,6 +128,8 @@ public function configuration(): Response
126128 $ builder = $ builder ->withClaim (ClaimsEnum::AuthorityHints->value , $ authorityHints );
127129 }
128130
131+ $ trustMarks = [];
132+
129133 if (
130134 is_array ($ trustMarkTokens = $ this ->moduleConfig ->getFederationTrustMarkTokens ()) &&
131135 (!empty ($ trustMarkTokens ))
@@ -145,7 +149,45 @@ public function configuration(): Response
145149 ClaimsEnum::TrustMark->value => $ token ,
146150 ];
147151 }, $ trustMarkTokens );
152+ }
153+
154+ if (
155+ is_array ($ dynamicTrustMarks = $ this ->moduleConfig ->getFederationDynamicTrustMarks ()) &&
156+ (!empty ($ dynamicTrustMarks ))
157+ ) {
158+ /**
159+ * @var non-empty-string $trustMarkId
160+ * @var non-empty-string $trustMarkIssuerId
161+ */
162+ foreach ($ dynamicTrustMarks as $ trustMarkId => $ trustMarkIssuerId ) {
163+ try {
164+ $ trustMarkIssuerConfigurationStatement = $ this ->federation ->entityStatementFetcher ()
165+ ->fromCacheOrWellKnownEndpoint ($ trustMarkIssuerId );
166+
167+ $ trustMarkEntity = $ this ->federation ->trustMarkFetcher ()->fromCacheOrFederationTrustMarkEndpoint (
168+ $ trustMarkId ,
169+ $ this ->moduleConfig ->getIssuer (),
170+ $ trustMarkIssuerConfigurationStatement ,
171+ );
172+
173+ $ trustMarks [] = [
174+ ClaimsEnum::TrustMarkId->value => $ trustMarkId ,
175+ ClaimsEnum::TrustMark->value => $ trustMarkEntity ->getToken (),
176+ ];
177+ } catch (\Throwable $ exception ) {
178+ $ this ->loggerService ->error (
179+ 'Error fetching Trust Mark: ' . $ exception ->getMessage (),
180+ [
181+ 'trustMarkId ' => $ trustMarkId ,
182+ 'subjectId ' => $ this ->moduleConfig ->getIssuer (),
183+ 'trustMarkIssuerId ' => $ trustMarkIssuerId ,
184+ ],
185+ );
186+ }
187+ }
188+ }
148189
190+ if (!empty ($ trustMarks )) {
149191 $ builder = $ builder ->withClaim (ClaimsEnum::TrustMarks->value , $ trustMarks );
150192 }
151193
0 commit comments