Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable optional client attestation in oid4vp #162

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LanguageExt;
using static System.String;

namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
namespace WalletFramework.Oid4Vc.ClientAttestation;

public record ClientAttestationPopDetails
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;

namespace WalletFramework.Oid4Vc.ClientAttestation;

public record CombinedWalletAttestation
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace WalletFramework.Oid4Vc.ClientAttestation;

public static class HttpClientExtensions
{
public static void AddClientAttestationPopHeader(this HttpClient client, CombinedWalletAttestation clientAttestation)
{
client.DefaultRequestHeaders.Add("OAuth-Client-Attestation", clientAttestation.WalletInstanceAttestationJwt);
client.DefaultRequestHeaders.Add("OAuth-Client-Attestation-PoP", clientAttestation.WalletInstanceAttestationPopJwt);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using WalletFramework.Core.Functional;
using WalletFramework.Core.Functional.Errors;

namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
namespace WalletFramework.Oid4Vc.ClientAttestation;

public struct WalletInstanceAttestationJwt
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
namespace WalletFramework.Oid4Vc.ClientAttestation;

public struct WalletInstanceAttestationPopJwt
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using WalletFramework.Oid4Vc.Oid4Vp.Models;

using WalletFramework.Oid4Vc.ClientAttestation;
namespace WalletFramework.Oid4Vc.Oid4Vp.Services;

/// <summary>
Expand All @@ -22,10 +23,12 @@ public interface IOid4VpClientService
/// </summary>
/// <param name="authorizationRequest"></param>
/// <param name="selectedCredentials"></param>
/// <param name="combinedWalletAttestation"></param>
/// <returns>
/// A task representing the asynchronous operation. The task result contains the Callback Url of the Authorization Response if present.
/// </returns>
Task<Uri?> SendAuthorizationResponseAsync(
AuthorizationRequest authorizationRequest,
IEnumerable<SelectedCredential> selectedCredentials);
IEnumerable<SelectedCredential> selectedCredentials,
CombinedWalletAttestation? combinedWalletAttestation = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LanguageExt;
using Microsoft.Extensions.Logging;
using SD_JWT.Models;
using WalletFramework.Oid4Vc.ClientAttestation;
using WalletFramework.Core.Credentials.Abstractions;
using WalletFramework.Core.Functional;
using WalletFramework.MdocLib;
Expand All @@ -10,7 +11,6 @@
using WalletFramework.MdocLib.Elements;
using WalletFramework.MdocLib.Security;
using WalletFramework.MdocVc;
using WalletFramework.Oid4Vc.Oid4Vci.Abstractions;
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
using WalletFramework.Oid4Vc.Oid4Vp.Models;
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Services;
Expand Down Expand Up @@ -82,7 +82,8 @@ public Oid4VpClientService(
/// <inheritdoc />
public async Task<Uri?> SendAuthorizationResponseAsync(
AuthorizationRequest authorizationRequest,
IEnumerable<SelectedCredential> selectedCredentials)
IEnumerable<SelectedCredential> selectedCredentials,
CombinedWalletAttestation? clientAttestation = null)
{
var credentials = selectedCredentials.ToList();

Expand Down Expand Up @@ -171,6 +172,8 @@ from path in field.Path.Select(path => path.TrimStart('$', '.'))

var httpClient = _httpClientFactory.CreateClient();
httpClient.DefaultRequestHeaders.Clear();
if (clientAttestation is not null)
httpClient.AddClientAttestationPopHeader(clientAttestation);

var json = SerializeObject(authorizationResponse);
var nameValueCollection = DeserializeObject<Dictionary<string, string>>(json)!.ToList();
Expand Down
Loading