17
17
using WalletFramework . Core . Functional ;
18
18
using WalletFramework . Core . Localization ;
19
19
using WalletFramework . MdocVc ;
20
+ using WalletFramework . Oid4Vc . Oid4Vci . Authorization . DPop . Models ;
20
21
using WalletFramework . SdJwtVc . Models . Records ;
21
22
using WalletFramework . SdJwtVc . Services . SdJwtVcHolderService ;
22
23
using static Newtonsoft . Json . JsonConvert ;
@@ -217,7 +218,7 @@ public async Task<Uri> InitiateAuthFlow(Uri uri, ClientOptions clientOptions, Op
217
218
clientOptions ,
218
219
validIssuerMetadata ,
219
220
authServerMetadata ,
220
- new List < CredentialConfigurationId > ( ) { validIssuerMetadata . CredentialConfigurationsSupported . Keys . First ( ) } ) ;
221
+ validIssuerMetadata . CredentialConfigurationsSupported . Keys . ToList ( ) ) ;
221
222
222
223
var context = await _agentProvider . GetContextAsync ( ) ;
223
224
await _authFlowSessionStorage . StoreAsync (
@@ -271,7 +272,7 @@ select credentialOrTransactionId.Match(
271
272
{
272
273
var record = sdJwt . Decoded . ToRecord ( configuration . AsT0 , issuerMetadata , response . KeyId ) ;
273
274
var context = await _agentProvider . GetContextAsync ( ) ;
274
- await _sdJwtService . SaveAsync ( context , record ) ;
275
+ await _sdJwtService . AddAsync ( context , record ) ;
275
276
return record ;
276
277
} ,
277
278
async mdoc =>
@@ -302,7 +303,7 @@ from metadata in _issuerMetadataService.ProcessMetadata(offer.CredentialIssuer,
302
303
}
303
304
304
305
/// <inheritdoc />
305
- public async Task < Validation < OneOf < SdJwtRecord , MdocRecord > > > RequestCredential ( IssuanceSession issuanceSession )
306
+ public async Task < Validation < List < OneOf < SdJwtRecord , MdocRecord > > > > RequestCredential ( IssuanceSession issuanceSession )
306
307
{
307
308
var context = await _agentProvider . GetContextAsync ( ) ;
308
309
@@ -313,8 +314,7 @@ public async Task<Validation<OneOf<SdJwtRecord, MdocRecord>>> RequestCredential(
313
314
. IssuerMetadata
314
315
. CredentialConfigurationsSupported
315
316
. Where ( config => session . AuthorizationData . CredentialConfigurationIds . Contains ( config . Key ) )
316
- . Select ( pair => pair . Value )
317
- . First ( ) ;
317
+ . Select ( pair => pair . Value ) ;
318
318
319
319
var scope = session
320
320
. AuthorizationData
@@ -336,37 +336,53 @@ public async Task<Validation<OneOf<SdJwtRecord, MdocRecord>>> RequestCredential(
336
336
var token = await _tokenService . RequestToken (
337
337
tokenRequest ,
338
338
session . AuthorizationData . AuthorizationServerMetadata ) ;
339
-
340
- var validResponse = await _credentialRequestService . RequestCredentials (
341
- credConfiguration ,
342
- session . AuthorizationData . IssuerMetadata ,
343
- token ,
344
- session . AuthorizationData . ClientOptions ) ;
339
+
340
+ List < OneOf < SdJwtRecord , MdocRecord > > credentials = new ( ) ;
341
+ //TODO: Make sure that it does not always request all available credConfigurations
342
+ foreach ( var configuration in credConfiguration )
343
+ {
344
+ var validResponse = await _credentialRequestService . RequestCredentials (
345
+ configuration ,
346
+ session . AuthorizationData . IssuerMetadata ,
347
+ token ,
348
+ session . AuthorizationData . ClientOptions ) ;
349
+
350
+ var result =
351
+ from response in validResponse
352
+ let cNonce = response . CNonce
353
+ let credentialOrTransactionId = response . CredentialOrTransactionId
354
+ select credentialOrTransactionId . Match (
355
+ async credential => await credential . Value . Match < Task < OneOf < SdJwtRecord , MdocRecord > > > (
356
+ async sdJwt =>
357
+ {
358
+ token = token . Match < OneOf < OAuthToken , DPopToken > > (
359
+ oAuth => oAuth with { CNonce = cNonce . ToNullable ( ) } ,
360
+ dPop => dPop with { Token = dPop . Token with { CNonce = cNonce . ToNullable ( ) } } ) ;
361
+
362
+ var record = sdJwt . Decoded . ToRecord ( configuration . AsT0 , session . AuthorizationData . IssuerMetadata , response . KeyId ) ;
363
+ await _sdJwtService . AddAsync ( context , record ) ;
364
+ return record ;
365
+ } ,
366
+ async mdoc =>
367
+ {
368
+ token = token . Match < OneOf < OAuthToken , DPopToken > > (
369
+ oAuth => oAuth with { CNonce = cNonce . ToNullable ( ) } ,
370
+ dPop => dPop with { Token = dPop . Token with { CNonce = cNonce . ToNullable ( ) } } ) ;
371
+
372
+ var displays = MdocFun . CreateMdocDisplays ( configuration . AsT1 ) ;
373
+ var record = mdoc . Decoded . ToRecord ( displays ) ;
374
+ await _mdocStorage . Add ( record ) ;
375
+ return record ;
376
+ } ) ,
377
+ // ReSharper disable once UnusedParameter.Local
378
+ transactionId => throw new NotImplementedException ( ) ) ;
379
+
380
+ await result . OnSuccess ( async task => credentials . Add ( await task ) ) ;
381
+ }
345
382
346
383
await _authFlowSessionStorage . DeleteAsync ( context , session . AuthFlowSessionState ) ;
347
384
348
- var result =
349
- from response in validResponse
350
- let credentialOrTransactionId = response . CredentialOrTransactionId
351
- select credentialOrTransactionId . Match (
352
- async credential => await credential . Value . Match < Task < OneOf < SdJwtRecord , MdocRecord > > > (
353
- async sdJwt =>
354
- {
355
- var record = sdJwt . Decoded . ToRecord ( credConfiguration . AsT0 , session . AuthorizationData . IssuerMetadata , response . KeyId ) ;
356
- await _sdJwtService . SaveAsync ( context , record ) ;
357
- return record ;
358
- } ,
359
- async mdoc =>
360
- {
361
- var displays = MdocFun . CreateMdocDisplays ( credConfiguration . AsT1 ) ;
362
- var record = mdoc . Decoded . ToRecord ( displays ) ;
363
- await _mdocStorage . Add ( record ) ;
364
- return record ;
365
- } ) ,
366
- // ReSharper disable once UnusedParameter.Local
367
- transactionId => throw new NotImplementedException ( ) ) ;
368
-
369
- return await result . OnSuccess ( task => task ) ;
385
+ return credentials ;
370
386
}
371
387
372
388
private static AuthorizationCodeParameters CreateAndStoreCodeChallenge ( )
0 commit comments