Skip to content

Commit a68ec20

Browse files
committed
Merge branch 'main' of github.com:openwallet-foundation-labs/wallet-framework-dotnet into client-attestation
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
2 parents 4b93c38 + f2d4506 commit a68ec20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1245
-1293
lines changed
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
using Newtonsoft.Json;
22

3-
namespace WalletFramework.Oid4Vc
3+
namespace WalletFramework.Oid4Vc;
4+
5+
/// <summary>
6+
/// Formatting extensions
7+
/// </summary>
8+
public static class FormattingExtensions
49
{
510
/// <summary>
6-
/// Formatting extensions
11+
/// Converts an <see cref="object"/> to json string using default converter.
712
/// </summary>
8-
public static class FormattingExtensions
9-
{
10-
/// <summary>
11-
/// Converts an <see cref="object"/> to json string using default converter.
12-
/// </summary>
13-
/// <param name="obj">The object.</param>
14-
/// <returns></returns>
15-
public static string ToJson(this object obj) =>
16-
JsonConvert.SerializeObject(obj, Formatting.None);
13+
/// <param name="obj">The object.</param>
14+
/// <returns></returns>
15+
public static string ToJson(this object obj) =>
16+
JsonConvert.SerializeObject(obj, Formatting.None);
1717

18-
/// <summary>
19-
/// Converts an object to json string using the provided <see cref="JsonSerializerSettings"/>
20-
/// </summary>
21-
/// <returns>The json.</returns>
22-
/// <param name="obj">Object.</param>
23-
/// <param name="settings">SerializerSettings.</param>
24-
public static string ToJson(this object obj, JsonSerializerSettings settings) =>
25-
JsonConvert.SerializeObject(obj, settings);
26-
}
27-
}
18+
/// <summary>
19+
/// Converts an object to json string using the provided <see cref="JsonSerializerSettings"/>
20+
/// </summary>
21+
/// <returns>The json.</returns>
22+
/// <param name="obj">Object.</param>
23+
/// <param name="settings">SerializerSettings.</param>
24+
public static string ToJson(this object obj, JsonSerializerSettings settings) =>
25+
JsonConvert.SerializeObject(obj, settings);
26+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// ReSharper disable once CheckNamespace
2-
namespace System.Runtime.CompilerServices
2+
namespace System.Runtime.CompilerServices;
3+
4+
// This is needed for the init property setter. This can be removed when updating to a newer C# Version.
5+
// https://stackoverflow.com/questions/64749385/predefined-type-system-runtime-compilerservices-isexternalinit-is-not-defined
6+
internal static class IsExternalInit
37
{
4-
// This is needed for the init property setter. This can be removed when updating to a newer C# Version.
5-
// https://stackoverflow.com/questions/64749385/predefined-type-system-runtime-compilerservices-isexternalinit-is-not-defined
6-
internal static class IsExternalInit
7-
{
8-
}
9-
}
8+
}

src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Abstractions/IDPopHttpClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface IDPopHttpClient
66
{
77
internal Task<DPopHttpResponse> Post(
88
Uri requestUri,
9-
HttpContent content,
10-
DPopConfig config);
9+
DPopConfig config,
10+
Func<HttpContent> getContent);
1111
}

src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/DPop/Implementations/DPopHttpClient.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public DPopHttpClient(
4040

4141
public async Task<DPopHttpResponse> Post(
4242
Uri requestUri,
43-
HttpContent content,
44-
DPopConfig config)
43+
DPopConfig config,
44+
Func<HttpContent> getContent)
4545
{
46-
var dPop = await GenerateDPopAsync(
46+
var dPop = await GenerateDPopHeaderAsync(
4747
config.KeyId,
4848
config.Audience,
4949
config.Nonce.ToNullable(),
@@ -53,9 +53,7 @@ public async Task<DPopHttpResponse> Post(
5353
token => _httpClient.WithDPopHeader(dPop).WithAuthorizationHeader(token),
5454
() => _httpClient.WithDPopHeader(dPop));
5555

56-
var response = await httpClient.PostAsync(
57-
requestUri,
58-
content);
56+
var response = await httpClient.PostAsync(requestUri, getContent());
5957

6058
await ThrowIfInvalidGrantError(response);
6159

@@ -64,15 +62,15 @@ public async Task<DPopHttpResponse> Post(
6462
{
6563
config = config with { Nonce = new DPopNonce(nonceStr) };
6664

67-
var newDpop = await GenerateDPopAsync(
65+
var newDpop = await GenerateDPopHeaderAsync(
6866
config.KeyId,
6967
config.Audience,
7068
config.Nonce.ToNullable(),
7169
config.OAuthToken.ToNullable()?.AccessToken);
7270

7371
httpClient.WithDPopHeader(newDpop);
7472

75-
response = await httpClient.PostAsync(requestUri, content);
73+
response = await httpClient.PostAsync(requestUri, getContent());
7674
}
7775

7876
await ThrowIfInvalidGrantError(response);
@@ -118,7 +116,7 @@ or System.Net.HttpStatusCode.Unauthorized
118116
return null;
119117
}
120118

121-
private async Task<string> GenerateDPopAsync(KeyId keyId, string audience, string? nonce, string? accessToken)
119+
private async Task<string> GenerateDPopHeaderAsync(KeyId keyId, string audience, string? nonce, string? accessToken)
122120
{
123121
var header = new Dictionary<string, object>
124122
{

src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Implementations/TokenService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public async Task<OneOf<OAuthToken, DPopToken>> RequestToken(
3838

3939
var result = await _dPopHttpClient.Post(
4040
uri,
41-
tokenRequest.ToFormUrlEncoded(),
42-
config);
41+
config,
42+
tokenRequest.ToFormUrlEncoded);
4343

4444
var token = DeserializeObject<OAuthToken>(await result.ResponseMessage.Content.ReadAsStringAsync())
4545
?? throw new InvalidOperationException("Failed to deserialize the token response");

src/WalletFramework.Oid4Vc/Oid4Vci/Authorization/Models/OAuthToken.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Newtonsoft.Json;
2-
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow;
32
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
43

54
namespace WalletFramework.Oid4Vc.Oid4Vci.Authorization.Models;

src/WalletFramework.Oid4Vc/Oid4Vci/CredConfiguration/Models/SdJwt/SdJwtConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Newtonsoft.Json;
21
using Newtonsoft.Json.Linq;
32
using WalletFramework.Core.Functional;
43
using WalletFramework.Core.Json;

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async Task<Validation<CredentialResponse>> ICredentialRequestService.RequestCred
102102
clientOptions);
103103

104104
var result = new MdocCredentialRequest(vciRequest, mdoc);
105-
return result.AsJson();
105+
return result.EncodeToJson();
106106
}
107107
);
108108

@@ -125,8 +125,8 @@ async Task<Validation<CredentialResponse>> ICredentialRequestService.RequestCred
125125

126126
var dPopResponse = await _dPopHttpClient.Post(
127127
issuerMetadata.CredentialEndpoint,
128-
content,
129-
config);
128+
config,
129+
() => content);
130130

131131
return dPopResponse.ResponseMessage;
132132
});

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LanguageExt;
2-
using Newtonsoft.Json.Linq;
32
using WalletFramework.MdocLib;
43
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.Mdoc;
54

@@ -25,7 +24,7 @@ public MdocCredentialRequest(CredentialRequest credentialRequest, MdocConfigurat
2524

2625
public static class MdocCredentialRequestFun
2726
{
28-
public static string AsJson(this MdocCredentialRequest request)
27+
public static string EncodeToJson(this MdocCredentialRequest request)
2928
{
3029
var json = request.VciRequest.EncodeToJson();
3130

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/SdJwt/SdJwtCredentialRequest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Newtonsoft.Json.Linq;
21
using WalletFramework.SdJwtVc.Models;
32

43
namespace WalletFramework.Oid4Vc.Oid4Vci.CredRequest.Models.SdJwt;

0 commit comments

Comments
 (0)