Skip to content

Commit 94e00b5

Browse files
committed
rename VciSessionState -> AuthCodeSessionState
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
1 parent 78bc636 commit 94e00b5

File tree

13 files changed

+88
-142
lines changed

13 files changed

+88
-142
lines changed

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Abstractions/IAuthFlowSessionStorage.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ public interface IAuthFlowSessionStorage
1414
/// Deletes the authorization session record by the session identifier.
1515
/// </summary>
1616
/// <param name="context">Agent Context</param>
17-
/// <param name="vciSessionState">Session State Identifier of a Authorization Code Flow session</param>
17+
/// <param name="authFlowSessionState">Session State Identifier of a Authorization Code Flow session</param>
1818
/// <returns></returns>
19-
Task<bool> DeleteAsync(IAgentContext context, VciSessionState vciSessionState);
19+
Task<bool> DeleteAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState);
2020

2121
/// <summary>
2222
/// Retrieves the authorization session record by the session identifier.
2323
/// </summary>
2424
/// <param name="context">Agent Context</param>
25-
/// <param name="vciSessionState">Session State Identifier of a Authorization Code Flow session</param>
25+
/// <param name="authFlowSessionState">Session State Identifier of a Authorization Code Flow session</param>
2626
/// <returns></returns>
27-
Task<AuthFlowSessionRecord> GetAsync(IAgentContext context, VciSessionState vciSessionState);
27+
Task<AuthFlowSessionRecord> GetAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState);
2828

2929
/// <summary>
3030
/// Stores the authorization session record.
@@ -35,11 +35,11 @@ public interface IAuthFlowSessionStorage
3535
/// Parameters required for the authorization during the VCI authorization code
3636
/// flow.
3737
/// </param>
38-
/// <param name="vciSessionState">Session State Identifier of a Authorization Code Flow session</param>
38+
/// <param name="authFlowSessionState">Session State Identifier of a Authorization Code Flow session</param>
3939
/// <returns></returns>
4040
Task<string> StoreAsync(
4141
IAgentContext agentContext,
4242
AuthorizationData authorizationData,
4343
AuthorizationCodeParameters authorizationCodeParameters,
44-
VciSessionState vciSessionState);
44+
AuthFlowSessionState authFlowSessionState);
4545
}
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 AuthFlowSessionStateError(string Value) : Error($"Invalid AuthFlowSessionState: {Value}");

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Errors/VciSessionIdError.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Errors/VciSessionStateError.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ public async Task<string> StoreAsync(
2626
IAgentContext agentContext,
2727
AuthorizationData authorizationData,
2828
AuthorizationCodeParameters authorizationCodeParameters,
29-
VciSessionState vciSessionState)
29+
AuthFlowSessionState authFlowSessionState)
3030
{
3131
var record = new AuthFlowSessionRecord(
3232
authorizationData,
3333
authorizationCodeParameters,
34-
vciSessionState);
34+
authFlowSessionState);
3535

3636
await _recordService.AddAsync(agentContext.Wallet, record, AuthFlowSessionRecordFun.EncodeToJson);
3737

3838
return record.Id;
3939
}
4040

4141
/// <inheritdoc />
42-
public async Task<AuthFlowSessionRecord> GetAsync(IAgentContext context, VciSessionState vciSessionState)
42+
public async Task<AuthFlowSessionRecord> GetAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState)
4343
{
44-
var record = await _recordService.GetAsync(context.Wallet, vciSessionState, AuthFlowSessionRecordFun.DecodeFromJson);
44+
var record = await _recordService.GetAsync(context.Wallet, authFlowSessionState, AuthFlowSessionRecordFun.DecodeFromJson);
4545
return record!;
4646
}
4747

4848
/// <inheritdoc />
49-
public async Task<bool> DeleteAsync(IAgentContext context, VciSessionState vciSessionState) =>
50-
await _recordService.DeleteAsync<AuthFlowSessionRecord>(context.Wallet, vciSessionState);
49+
public async Task<bool> DeleteAsync(IAgentContext context, AuthFlowSessionState authFlowSessionState) =>
50+
await _recordService.DeleteAsync<AuthFlowSessionRecord>(context.Wallet, authFlowSessionState);
5151
}
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 state during the VCI Authorization Code Flow.
10+
/// </summary>
11+
public struct AuthFlowSessionState
12+
{
13+
/// <summary>
14+
/// Gets the value of the state identifier.
15+
/// </summary>
16+
private string Value { get; }
17+
18+
private AuthFlowSessionState(string value) => Value = value;
19+
20+
/// <summary>
21+
/// Returns the value of the state identifier.
22+
/// </summary>
23+
/// <param name="authFlowSessionState"></param>
24+
/// <returns></returns>
25+
public static implicit operator string(AuthFlowSessionState authFlowSessionState) => authFlowSessionState.Value;
26+
27+
public static Validation<AuthFlowSessionState> ValidAuthFlowSessionState(string authFlowSessionState)
28+
{
29+
if (!Guid.TryParse(authFlowSessionState, out _))
30+
{
31+
return new AuthFlowSessionStateError(authFlowSessionState);
32+
}
33+
34+
return new AuthFlowSessionState(authFlowSessionState);
35+
}
36+
37+
public static AuthFlowSessionState CreateAuthFlowSessionState()
38+
{
39+
var guid = Guid.NewGuid().ToString();
40+
return new AuthFlowSessionState(guid);
41+
}
42+
}
43+
44+
public static class AuthFlowSessionStateFun
45+
{
46+
public static AuthFlowSessionState DecodeFromJson(JValue json) => AuthFlowSessionState
47+
.ValidAuthFlowSessionState(json.ToString(CultureInfo.InvariantCulture))
48+
.UnwrapOrThrow(new InvalidOperationException("AuthFlowSessionState is corrupt"));
49+
}

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Models/IssuanceSession.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public record IssuanceSession
1111
/// <summary>
1212
/// Gets the session identifier.
1313
/// </summary>
14-
public VciSessionState VciSessionState { get; }
14+
public AuthFlowSessionState AuthFlowSessionState { get; }
1515

1616
/// <summary>
1717
/// Gets the actual authorization code that is received from the authorization server upon successful authorization.
1818
/// </summary>
1919
public string Code { get; }
2020

21-
private IssuanceSession(VciSessionState vciSessionState, string code) => (VciSessionState, Code) = (vciSessionState, code);
21+
private IssuanceSession(AuthFlowSessionState authFlowSessionState, string code) => (AuthFlowSessionState, Code) = (authFlowSessionState, code);
2222

2323
/// <summary>
2424
/// Creates a new instance of <see cref="IssuanceSession"/> from the given <see cref="Uri"/>.
@@ -37,8 +37,8 @@ public static IssuanceSession FromUri(Uri uri)
3737
}
3838

3939
var sessionStateParam = queryParams.Get("state");
40-
var vciSessionState = VciSessionState.ValidVciSessionState(sessionStateParam).Fallback(VciSessionState.CreateVciSessionState());
40+
var authFlowSessionState = AuthFlowSessionState.ValidAuthFlowSessionState(sessionStateParam).Fallback(AuthFlowSessionState.CreateAuthFlowSessionState());
4141

42-
return new IssuanceSession(vciSessionState, code);
42+
return new IssuanceSession(authFlowSessionState, code);
4343
}
4444
}

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Models/PushedAuthorizationRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal record PushedAuthorizationRequest
2121
public string CodeChallengeMethod { get; }
2222

2323
[JsonProperty("state", NullValueHandling = NullValueHandling.Ignore)]
24-
public string VciSessionState { get; }
24+
public string AuthFlowSessionState { get; }
2525

2626
[JsonProperty("authorization_details", NullValueHandling = NullValueHandling.Ignore)]
2727
public AuthorizationDetails[]? AuthorizationDetails { get; }
@@ -42,7 +42,7 @@ internal record PushedAuthorizationRequest
4242
public string? Resource { get; }
4343

4444
public PushedAuthorizationRequest(
45-
VciSessionState vciSessionState,
45+
AuthFlowSessionState authFlowSessionState,
4646
ClientOptions clientOptions,
4747
AuthorizationCodeParameters authorizationCodeParameters,
4848
AuthorizationDetails[]? authorizationDetails,
@@ -56,7 +56,7 @@ public PushedAuthorizationRequest(
5656
WalletIssuer = clientOptions.WalletIssuer;
5757
CodeChallenge = authorizationCodeParameters.Challenge;
5858
CodeChallengeMethod = authorizationCodeParameters.CodeChallengeMethod;
59-
VciSessionState = vciSessionState;
59+
AuthFlowSessionState = authFlowSessionState;
6060
AuthorizationDetails = authorizationDetails;
6161
IssuerState = issuerState;
6262
UserHint = userHint;
@@ -83,8 +83,8 @@ public FormUrlEncodedContent ToFormUrlEncoded()
8383
if (!string.IsNullOrEmpty(CodeChallengeMethod))
8484
keyValuePairs.Add(new KeyValuePair<string, string>("code_challenge_method", CodeChallengeMethod));
8585

86-
if (!string.IsNullOrEmpty(VciSessionState))
87-
keyValuePairs.Add(new KeyValuePair<string, string>("state", VciSessionState));
86+
if (!string.IsNullOrEmpty(AuthFlowSessionState))
87+
keyValuePairs.Add(new KeyValuePair<string, string>("state", AuthFlowSessionState));
8888

8989
if (AuthorizationDetails != null)
9090
keyValuePairs.Add(new KeyValuePair<string, string>("authorization_details", SerializeObject(AuthorizationDetails)));

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Models/VciSessionId.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/WalletFramework.Oid4Vc/Oid4Vci/AuthFlow/Models/VciSessionState.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)