@@ -189,7 +189,7 @@ private async Task<Validation<AuthorizationRequestCancellation, Option<ClientMet
189
189
return await authorizationRequest . ClientMetadata . AsOption ( ) . Match (
190
190
clientMetadata =>
191
191
{
192
- if ( ! IsVpFormatsSupported ( authorizationRequest ) )
192
+ if ( clientMetadata . IsVpFormatsSupported ( authorizationRequest . Requirements ) )
193
193
{
194
194
var error = new VpFormatsNotSupportedError ( "The provided vp_formats_supported values are not supported" ) ;
195
195
var authorizationCancellation = new AuthorizationRequestCancellation ( authorizationRequest . GetResponseUriMaybe ( ) , [ error ] ) ;
@@ -210,8 +210,11 @@ private async Task<Validation<AuthorizationRequestCancellation, Option<ClientMet
210
210
var response = await httpClient . GetAsync ( authorizationRequest . ClientMetadataUri ) ;
211
211
var clientMetadataJsonString = await response . Content . ReadAsStringAsync ( ) ;
212
212
var clientMetadata = DeserializeObject < ClientMetadata > ( clientMetadataJsonString ) ;
213
-
214
- if ( ! IsVpFormatsSupported ( authorizationRequest ) )
213
+
214
+ if ( clientMetadata == null )
215
+ return Option < ClientMetadata > . None ;
216
+
217
+ if ( clientMetadata . IsVpFormatsSupported ( authorizationRequest . Requirements ) )
215
218
{
216
219
var error = new VpFormatsNotSupportedError ( "The provided vp_formats_supported values are not supported" ) ;
217
220
var authorizationCancellation = new AuthorizationRequestCancellation ( authorizationRequest . GetResponseUriMaybe ( ) , [ error ] ) ;
@@ -221,78 +224,4 @@ private async Task<Validation<AuthorizationRequestCancellation, Option<ClientMet
221
224
return clientMetadata . AsOption ( ) ;
222
225
} ) ;
223
226
}
224
-
225
-
226
- private bool IsVpFormatsSupported ( AuthorizationRequest authorizationRequest )
227
- {
228
- return authorizationRequest . Requirements . Match (
229
- dcql =>
230
- {
231
- var walletMetadata = WalletMetadata . CreateDefault ( ) ;
232
-
233
- var ( sdJwtRequested , mdocRequested ) =
234
- ( dcql . CredentialQueries . Any ( query => query . Format == Constants . SdJwtDcFormat || query . Format == Constants . SdJwtVcFormat ) ,
235
- dcql . CredentialQueries . Any ( query => query . Format == Constants . MdocFormat ) ) ;
236
-
237
- return ( sdJwtRequested , mdocRequested ) switch
238
- {
239
- ( true , false ) => IsSdJwtVpFormatSupported ( authorizationRequest , walletMetadata ) ,
240
- ( false , true ) => IsMdocVpFormatSupported ( authorizationRequest , walletMetadata ) ,
241
- ( true , true ) => IsSdJwtVpFormatSupported ( authorizationRequest , walletMetadata ) &&
242
- IsMdocVpFormatSupported ( authorizationRequest , walletMetadata ) ,
243
- _ => true
244
- } ;
245
- } ,
246
- _ => true ) ;
247
- }
248
-
249
- private bool IsMdocVpFormatSupported ( AuthorizationRequest authorizationRequest , WalletMetadata walletMetadata )
250
- {
251
- var rpSupportedVpFormats = authorizationRequest . ClientMetadata ? . VpFormatsSupported ?? authorizationRequest . ClientMetadata ? . VpFormats ;
252
- var walletMetadataSupportedVpFormats = walletMetadata . VpFormatsSupported ;
253
-
254
- if ( rpSupportedVpFormats ? . MDocFormat == null )
255
- return true ;
256
-
257
- if ( rpSupportedVpFormats . MDocFormat . IssuerAuthAlgValues != null &&
258
- ! rpSupportedVpFormats . MDocFormat . IssuerAuthAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . MDocFormat ! . IssuerAuthAlgValues ! . Contains ( clientAlg ) ) )
259
- return false ;
260
-
261
- if ( rpSupportedVpFormats . MDocFormat . DeviceAuthAlgValues != null &&
262
- ! rpSupportedVpFormats . MDocFormat . DeviceAuthAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . MDocFormat ! . DeviceAuthAlgValues ! . Contains ( clientAlg ) ) )
263
- return false ;
264
-
265
- return true ;
266
- }
267
-
268
- private bool IsSdJwtVpFormatSupported ( AuthorizationRequest authorizationRequest , WalletMetadata walletMetadata )
269
- {
270
- var rpSupportedVpFormats = authorizationRequest . ClientMetadata ? . VpFormatsSupported ?? authorizationRequest . ClientMetadata ? . VpFormats ;
271
- var walletMetadataSupportedVpFormats = walletMetadata . VpFormatsSupported ;
272
-
273
- if ( rpSupportedVpFormats ? . SdJwtDcFormat != null )
274
- {
275
- if ( rpSupportedVpFormats . SdJwtDcFormat . IssuerSignedJwtAlgValues != null &&
276
- ! rpSupportedVpFormats . SdJwtDcFormat . IssuerSignedJwtAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . SdJwtDcFormat ! . IssuerSignedJwtAlgValues ! . Contains ( clientAlg ) ) )
277
- return false ;
278
-
279
- if ( rpSupportedVpFormats . SdJwtDcFormat . KeyBindingJwtAlgValues != null &&
280
- ! rpSupportedVpFormats . SdJwtDcFormat . KeyBindingJwtAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . SdJwtDcFormat ! . KeyBindingJwtAlgValues ! . Contains ( clientAlg ) ) )
281
- return false ;
282
- }
283
-
284
- //TODO: Remove SdJwtVcFormat in the future as it is deprecated (kept for now for backwards compatibility)
285
- if ( rpSupportedVpFormats ? . SdJwtVcFormat != null )
286
- {
287
- if ( rpSupportedVpFormats . SdJwtVcFormat . IssuerSignedJwtAlgValues != null &&
288
- ! rpSupportedVpFormats . SdJwtVcFormat . IssuerSignedJwtAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . SdJwtVcFormat ! . IssuerSignedJwtAlgValues ! . Contains ( clientAlg ) ) )
289
- return false ;
290
-
291
- if ( rpSupportedVpFormats . SdJwtVcFormat . KeyBindingJwtAlgValues != null &&
292
- ! rpSupportedVpFormats . SdJwtVcFormat . KeyBindingJwtAlgValues . Any ( clientAlg => walletMetadataSupportedVpFormats . SdJwtVcFormat ! . KeyBindingJwtAlgValues ! . Contains ( clientAlg ) ) )
293
- return false ;
294
- }
295
-
296
- return true ;
297
- }
298
227
}
0 commit comments