Skip to content

Commit a4a1ee6

Browse files
committed
c'' interfaces
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
1 parent ba3c20a commit a4a1ee6

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-0
lines changed

src/WalletFramework.Oid4Vc/Oid4Vci/Abstractions/IOid4VciClientService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using WalletFramework.Core.Localization;
66
using WalletFramework.MdocVc;
77
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
8+
using WalletFramework.Oid4Vc.Oid4Vci.OnDemandCredential.Models;
89
using WalletFramework.SdJwtVc.Models.Records;
910

1011
namespace WalletFramework.Oid4Vc.Oid4Vci.Abstractions;
@@ -40,6 +41,10 @@ public interface IOid4VciClientService
4041
/// </returns>
4142
Task<Validation<List<OneOf<SdJwtRecord, MdocRecord>>>> RequestCredential(IssuanceSession issuanceSession);
4243

44+
Task<Validation<List<OneOf<SdJwtRecord, MdocRecord>>>> RequestOnDemandCredential(IssuanceSession issuanceSession);
45+
//Add Acces TOken to issaunce session
46+
//Dont dletet issaunce session
47+
4348
/// <summary>
4449
/// Processes a credential offer
4550
/// </summary>

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Implementations/AuthFlowSessionStorage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ public async Task<AuthFlowSessionRecord> GetAsync(IAgentContext context, AuthFlo
4848
/// <inheritdoc />
4949
public async Task<bool> DeleteAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState) =>
5050
await _recordService.DeleteAsync<AuthFlowSessionRecord>(context.Wallet, authFlowSessionState);
51+
52+
/// <inheritdoc />
53+
public async Task<bool> UpdateAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState) =>
54+
await _recordService.DeleteAsync<AuthFlowSessionRecord>(context.Wallet, authFlowSessionState);
5155
}

src/WalletFramework.Oid4Vc/Oid4Vci/Implementations/Oid4VciClientService.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,88 @@ select credentialOrTransactionId.Match(
384384

385385
return credentials;
386386
}
387+
388+
/// <inheritdoc />
389+
public async Task<Validation<List<OneOf<SdJwtRecord, MdocRecord>>>> RequestOnDemandCredential(IssuanceSession issuanceSession)
390+
{
391+
var context = await _agentProvider.GetContextAsync();
392+
393+
var session = await _authFlowSessionStorage.GetAsync(context, issuanceSession.AuthFlowSessionState);
394+
395+
var credConfiguration = session
396+
.AuthorizationData
397+
.IssuerMetadata
398+
.CredentialConfigurationsSupported
399+
.Where(config => session.AuthorizationData.CredentialConfigurationIds.Contains(config.Key))
400+
.Select(pair => pair.Value);
401+
402+
var scope = session
403+
.AuthorizationData
404+
.IssuerMetadata
405+
.CredentialConfigurationsSupported.First().Value.Match(
406+
sdJwtConfig => sdJwtConfig.CredentialConfiguration.Scope.OnSome(scope => scope.ToString()),
407+
mdDocConfig => mdDocConfig.CredentialConfiguration.Scope.OnSome(scope => scope.ToString()));
408+
409+
var tokenRequest = new TokenRequest
410+
{
411+
GrantType = AuthorizationCodeGrantTypeIdentifier,
412+
RedirectUri = session.AuthorizationData.ClientOptions.RedirectUri,
413+
CodeVerifier = session.AuthorizationCodeParameters.Verifier,
414+
Code = issuanceSession.Code,
415+
Scope = scope.ToNullable(),
416+
ClientId = session.AuthorizationData.ClientOptions.ClientId
417+
};
418+
419+
var token = await _tokenService.RequestToken(
420+
tokenRequest,
421+
session.AuthorizationData.AuthorizationServerMetadata);
422+
423+
List<OneOf<SdJwtRecord, MdocRecord>> credentials = new();
424+
//TODO: Make sure that it does not always request all available credConfigurations
425+
foreach (var configuration in credConfiguration)
426+
{
427+
var validResponse = await _credentialRequestService.RequestCredentials(
428+
configuration,
429+
session.AuthorizationData.IssuerMetadata,
430+
token,
431+
session.AuthorizationData.ClientOptions);
432+
433+
var result =
434+
from response in validResponse
435+
let cNonce = response.CNonce
436+
let credentialOrTransactionId = response.CredentialOrTransactionId
437+
select credentialOrTransactionId.Match(
438+
async credential => await credential.Value.Match<Task<OneOf<SdJwtRecord, MdocRecord>>>(
439+
async sdJwt =>
440+
{
441+
token = token.Match<OneOf<OAuthToken, DPopToken>>(
442+
oAuth => oAuth with { CNonce = cNonce.ToNullable()},
443+
dPop => dPop with { Token = dPop.Token with {CNonce = cNonce.ToNullable()}});
444+
445+
var record = sdJwt.Decoded.ToRecord(configuration.AsT0, response.KeyId);
446+
return record;
447+
},
448+
async mdoc =>
449+
{
450+
token = token.Match<OneOf<OAuthToken, DPopToken>>(
451+
oAuth => oAuth with { CNonce = cNonce.ToNullable()},
452+
dPop => dPop with { Token = dPop.Token with {CNonce = cNonce.ToNullable()}});
453+
454+
var displays = MdocFun.CreateMdocDisplays(configuration.AsT1);
455+
var record = mdoc.Decoded.ToRecord(displays, response.KeyId);
456+
return record;
457+
}),
458+
// ReSharper disable once UnusedParameter.Local
459+
transactionId => throw new NotImplementedException());
460+
461+
await result.OnSuccess(async task => credentials.Add(await task));
462+
}
463+
464+
// await _authFlowSessionStorage.
465+
await _authFlowSessionStorage.DeleteAsync(context, session.AuthFlowSessionState);
466+
467+
return credentials;
468+
}
387469

388470
private static AuthorizationCodeParameters CreateAndStoreCodeChallenge()
389471
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace WalletFramework.Oid4Vc.Oid4Vci.OnDemandCredential.Models;
2+
3+
public record IssuerSignedCredential
4+
{
5+
6+
};

src/WalletFramework.Oid4Vc/Oid4Vp/Services/IOid4VpClientService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using WalletFramework.Oid4Vc.Oid4Vp.Models;
22

33
using WalletFramework.Oid4Vc.ClientAttestation;
4+
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
5+
46
namespace WalletFramework.Oid4Vc.Oid4Vp.Services;
57

68
/// <summary>
@@ -31,4 +33,11 @@ public interface IOid4VpClientService
3133
AuthorizationRequest authorizationRequest,
3234
IEnumerable<SelectedCredential> selectedCredentials,
3335
CombinedWalletAttestation? combinedWalletAttestation = null);
36+
37+
Task<Uri?> SendAuthorizationResponseAsync(
38+
AuthorizationRequest authorizationRequest,
39+
IEnumerable<SelectedCredential> selectedCredentials,
40+
IssuanceSession issuanceSession,
41+
CombinedWalletAttestation? combinedWalletAttestation = null);
42+
//issuer signing key
3443
}

src/WalletFramework.Oid4Vc/Oid4Vp/Services/Oid4VpClientService.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using WalletFramework.MdocLib.Elements;
1212
using WalletFramework.MdocLib.Security;
1313
using WalletFramework.MdocVc;
14+
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
1415
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
1516
using WalletFramework.Oid4Vc.Oid4Vp.Models;
1617
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Services;
@@ -164,6 +165,16 @@ from path in field.Path.Select(path => path.TrimStart('$', '.'))
164165
var presentationMap = await task;
165166
presentationMaps.Add(presentationMap);
166167
}
168+
169+
170+
//
171+
// if (issuerSignature)
172+
// {
173+
// var stringe = presentationMaps.First().Presentation[..presentationMaps.First().Presentation.LastIndexOf('.')];
174+
//
175+
// var client = _httpClientFactory.CreateClient();
176+
// client.PostAsync(new Uri("https://demo.pid-issuer.bundesdruckerei.de/c2"), stringe)
177+
// }
167178

168179
var authorizationResponse = await _oid4VpHaipClient.CreateAuthorizationResponseAsync(
169180
authorizationRequest,
@@ -276,6 +287,12 @@ await _oid4VpRecordService.StoreAsync(
276287
return null;
277288
}
278289
}
290+
291+
public Task<Uri?> SendAuthorizationResponseAsync(AuthorizationRequest authorizationRequest, IEnumerable<SelectedCredential> selectedCredentials,
292+
IssuanceSession issuanceSession, CombinedWalletAttestation? combinedWalletAttestation = null)
293+
{
294+
throw new NotImplementedException();
295+
}
279296
}
280297

281298
internal static class SdJwtRecordExtensions

0 commit comments

Comments
 (0)