From e2f39baa4d1d44e2bfb0b7845985fcf5c00e53b9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 22 Jul 2024 09:47:27 +0200 Subject: [PATCH] adjust dpop Signed-off-by: Kevin --- .../Authorization/DPop/Abstractions/IDPopHttpClient.cs | 4 ++-- .../DPop/Implementations/DPopHttpClient.cs | 10 ++++------ .../Authorization/Implementations/TokenService.cs | 4 ++-- .../Implementations/CredentialRequestService.cs | 6 +++--- .../CredRequest/Models/Mdoc/MdocCredentialRequest.cs | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Abstractions/IDPopHttpClient.cs b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Abstractions/IDPopHttpClient.cs index 901fafc8..de110464 100644 --- a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Abstractions/IDPopHttpClient.cs +++ b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Abstractions/IDPopHttpClient.cs @@ -6,6 +6,6 @@ public interface IDPopHttpClient { internal Task Post( Uri requestUri, - HttpContent content, - DPopConfig config); + DPopConfig config, + Func getContent); } diff --git a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Implementations/DPopHttpClient.cs b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Implementations/DPopHttpClient.cs index 6e747ce9..dfea1ef4 100644 --- a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Implementations/DPopHttpClient.cs +++ b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Implementations/DPopHttpClient.cs @@ -31,8 +31,8 @@ public DPopHttpClient( public async Task Post( Uri requestUri, - HttpContent content, - DPopConfig config) + DPopConfig config, + Func getContent) { var dPop = await _keyStore.GenerateDPopProofOfPossessionAsync( config.KeyId, @@ -44,9 +44,7 @@ public async Task Post( token => _httpClient.WithDPopHeader(dPop).WithAuthorizationHeader(token), () => _httpClient.WithDPopHeader(dPop)); - var response = await httpClient.PostAsync( - requestUri, - content); + var response = await httpClient.PostAsync(requestUri, getContent()); await ThrowIfInvalidGrantError(response); @@ -63,7 +61,7 @@ public async Task Post( httpClient.WithDPopHeader(newDpop); - response = await httpClient.PostAsync(requestUri, content); + response = await httpClient.PostAsync(requestUri, getContent()); } await ThrowIfInvalidGrantError(response); diff --git a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Implementations/TokenService.cs b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Implementations/TokenService.cs index 5ecd19b0..b3f66633 100644 --- a/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Implementations/TokenService.cs +++ b/src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Implementations/TokenService.cs @@ -38,8 +38,8 @@ public async Task> RequestToken( var result = await _dPopHttpClient.Post( uri, - tokenRequest.ToFormUrlEncoded(), - config); + config, + tokenRequest.ToFormUrlEncoded); var token = DeserializeObject(await result.ResponseMessage.Content.ReadAsStringAsync()) ?? throw new InvalidOperationException("Failed to deserialize the token response"); diff --git a/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs b/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs index dd9be71c..aebcdcaa 100644 --- a/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs +++ b/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs @@ -98,7 +98,7 @@ async Task> ICredentialRequestService.RequestCred clientOptions); var result = new MdocCredentialRequest(vciRequest, mdoc); - return result.AsJson(); + return result.EncodeToJson(); } ); @@ -121,8 +121,8 @@ async Task> ICredentialRequestService.RequestCred var dPopResponse = await _dPopHttpClient.Post( issuerMetadata.CredentialEndpoint, - content, - config); + config, + () => content); return dPopResponse.ResponseMessage; }); diff --git a/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs b/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs index 9795247c..dbe4650f 100644 --- a/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs +++ b/src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs @@ -24,7 +24,7 @@ public MdocCredentialRequest(CredentialRequest credentialRequest, MdocConfigurat public static class MdocCredentialRequestFun { - public static string AsJson(this MdocCredentialRequest request) + public static string EncodeToJson(this MdocCredentialRequest request) { var json = request.VciRequest.EncodeToJson();