Skip to content

Commit ea0833f

Browse files
committed
Merge branch 'main' of github.com:openwallet-foundation-labs/wallet-framework-dotnet into refactor-auth-flow-session-handling
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
2 parents 2922354 + f9b3ee9 commit ea0833f

Some content is hidden

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

44 files changed

+1270
-1261
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+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using WalletFramework.Core.Functional;
2+
3+
namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Errors;
4+
5+
public record VciSessionIdError(string Value) : Error($"Invalid VciSessionId: {Value}");
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Globalization;
2+
using Newtonsoft.Json.Linq;
3+
using WalletFramework.Core.Functional;
4+
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Errors;
5+
6+
namespace WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
7+
8+
/// <summary>
9+
/// Identifier of the authorization session during the VCI Authorization Code Flow.
10+
/// </summary>
11+
public struct VciSessionId
12+
{
13+
/// <summary>
14+
/// Gets the value of the session identifier.
15+
/// </summary>
16+
private string Value { get; }
17+
18+
private VciSessionId(string value) => Value = value;
19+
20+
/// <summary>
21+
/// Returns the value of the session identifier.
22+
/// </summary>
23+
/// <param name="sessionId"></param>
24+
/// <returns></returns>
25+
public static implicit operator string(VciSessionId sessionId) => sessionId.Value;
26+
27+
public static Validation<VciSessionId> ValidSessionId(string sessionId)
28+
{
29+
if (!Guid.TryParse(sessionId, out _))
30+
{
31+
return new VciSessionIdError(sessionId);
32+
}
33+
34+
return new VciSessionId(sessionId);
35+
}
36+
37+
public static VciSessionId CreateSessionId()
38+
{
39+
var guid = Guid.NewGuid().ToString();
40+
return new VciSessionId(guid);
41+
}
42+
}
43+
44+
public static class VciSessionIdFun
45+
{
46+
public static VciSessionId DecodeFromJson(JValue json) => VciSessionId
47+
.ValidSessionId(json.ToString(CultureInfo.InvariantCulture))
48+
.UnwrapOrThrow(new InvalidOperationException("SessionId is corrupt"));
49+
}

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/Models/Mdoc/MdocCredentialRequest.cs

Lines changed: 0 additions & 1 deletion
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

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;
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
using System.Net;
22

3-
namespace WalletFramework.Oid4Vc.Oid4Vci.Exceptions
3+
namespace WalletFramework.Oid4Vc.Oid4Vci.Exceptions;
4+
5+
/// <summary>
6+
/// Represents an exception thrown when the grant within the Oid4Vci flow is invalid (e.g. wrong tx_code).
7+
/// </summary>
8+
public class Oid4VciInvalidGrantException : Exception
49
{
510
/// <summary>
6-
/// Represents an exception thrown when the grant within the Oid4Vci flow is invalid (e.g. wrong tx_code).
11+
/// Initializes a new instance of the <see cref="Oid4VciInvalidGrantException"/> class.
712
/// </summary>
8-
public class Oid4VciInvalidGrantException : Exception
13+
/// <param name="statusCode">The StatusCode associated with the thrown Exception</param>
14+
public Oid4VciInvalidGrantException(HttpStatusCode statusCode)
15+
: base($"Invalid grant error. Status Code is {statusCode}")
916
{
10-
/// <summary>
11-
/// Initializes a new instance of the <see cref="Oid4VciInvalidGrantException"/> class.
12-
/// </summary>
13-
/// <param name="statusCode">The StatusCode associated with the thrown Exception</param>
14-
public Oid4VciInvalidGrantException(HttpStatusCode statusCode)
15-
: base($"Invalid grant error. Status Code is {statusCode}")
16-
{
17-
}
1817
}
19-
}
18+
}

src/WalletFramework.Oid4Vc/Oid4Vci/Issuer/Abstractions/IIssuerMetadataService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using WalletFramework.Core.Functional;
22
using WalletFramework.Core.Localization;
33
using WalletFramework.Oid4Vc.Oid4Vci.Issuer.Models;
4-
using WalletFramework.Oid4Vc.Oid4Vci.Models;
54

65
namespace WalletFramework.Oid4Vc.Oid4Vci.Issuer.Abstractions;
76

0 commit comments

Comments
 (0)