Skip to content

Commit cd6331b

Browse files
authored
Code Refactoring & Polishing (#16)
* Code Refactoring & Polishing * Core Project Cleanup * Remove Base64Url Duplicated Methods * Remove Session Domain Interfaces & EFCore Session Multi Tenant Enhancements * Added ISessionValidator * Added TenantKey Value Object * Refactoring on Credential Projects * Main Refactoring * Fix Compiler Warnings & Last Refactorings
1 parent a6955d9 commit cd6331b

File tree

757 files changed

+14137
-16416
lines changed

Some content is hidden

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

757 files changed

+14137
-16416
lines changed

samples/UAuthHub/CodeBeam.UltimateAuth.Sample.UAuthHub/Components/Pages/Home.razor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ protected override async Task OnParametersSetAsync()
2727
return;
2828
}
2929

30-
_state = await HubFlowReader.GetStateAsync(new HubSessionId(HubKey));
30+
if (!HubSessionId.TryParse(HubKey, out var hubSessionId))
31+
_state = await HubFlowReader.GetStateAsync(hubSessionId);
3132
}
3233

3334
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -74,7 +75,10 @@ private async Task ProgrammaticPkceLogin()
7475
if (hub is null)
7576
return;
7677

77-
var credentials = await HubCredentialResolver.ResolveAsync(new HubSessionId(HubKey));
78+
if (!HubSessionId.TryParse(HubKey, out var hubSessionId))
79+
return;
80+
81+
var credentials = await HubCredentialResolver.ResolveAsync(hubSessionId);
7882

7983
var request = new PkceLoginRequest
8084
{

samples/UAuthHub/CodeBeam.UltimateAuth.Sample.UAuthHub/Controllers/HubLoginController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CodeBeam.UltimateAuth.Core.Abstractions;
22
using CodeBeam.UltimateAuth.Core.Domain;
3+
using CodeBeam.UltimateAuth.Core.MultiTenancy;
34
using CodeBeam.UltimateAuth.Core.Options;
45
using CodeBeam.UltimateAuth.Server.Options;
56
using CodeBeam.UltimateAuth.Server.Stores;
@@ -41,7 +42,7 @@ public async Task<IActionResult> BeginLogin(
4142
hubSessionId: hubSessionId,
4243
flowType: HubFlowType.Login,
4344
clientProfile: client_profile,
44-
tenantId: null,
45+
tenant: TenantKeys.System,
4546
returnUrl: return_url,
4647
payload: payload,
4748
expiresAt: _clock.UtcNow.Add(_options.Hub.FlowLifetime));

samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/Components/Pages/Home.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<MudText>UAuthState @(StateManager.State.IsAuthenticated == true ? "Authenticated" : "Not Authenticated") - UserId:@(StateManager.State.UserKey)</MudText>
6161
<AuthorizeView>
6262
<Authorized>
63-
<MudText>Authorized context is shown. @context.User.Identity.IsAuthenticated</MudText>
63+
<MudText>Authorized context is shown. @context?.User?.Identity?.IsAuthenticated</MudText>
6464
</Authorized>
6565
<NotAuthorized>
6666
<MudText>Not Authorized context is shown.</MudText>

samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using CodeBeam.UltimateAuth.Core.Domain;
77
using CodeBeam.UltimateAuth.Core.Extensions;
88
using CodeBeam.UltimateAuth.Core.Infrastructure;
9+
using CodeBeam.UltimateAuth.Core.MultiTenancy;
910
using CodeBeam.UltimateAuth.Credentials;
1011
using CodeBeam.UltimateAuth.Credentials.InMemory.Extensions;
1112
using CodeBeam.UltimateAuth.Credentials.Reference;
@@ -112,13 +113,9 @@
112113
app.MapOpenApi();
113114
app.MapScalarApiReference();
114115
using var scope = app.Services.CreateScope();
115-
//scope.ServiceProvider.GetRequiredService<IUserLifecycleStore>();
116-
//scope.ServiceProvider.GetRequiredService<IUserProfileStore>();
117-
//scope.ServiceProvider.GetRequiredService<IUserIdentifierStore>();
118-
//scope.ServiceProvider.GetRequiredService<ICredentialStore<UserKey>>();
119116
var seedRunner = scope.ServiceProvider.GetRequiredService<SeedRunner>();
120117

121-
await seedRunner.RunAsync(tenantId: null);
118+
await seedRunner.RunAsync(null);
122119
}
123120

124121
app.UseHttpsRedirection();

samples/blazor-standalone-wasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm/Pages/Home.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm.Pages
1111
public partial class Home
1212
{
1313
[CascadingParameter]
14-
public UAuthState Auth { get; set; }
14+
public UAuthState Auth { get; set; } = null!;
1515

1616
private string? _username;
1717
private string? _password;
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using CodeBeam.UltimateAuth.Client.Contracts;
22

3-
namespace CodeBeam.UltimateAuth.Client.Utilities
3+
namespace CodeBeam.UltimateAuth.Client.Utilities;
4+
5+
public interface IBrowserStorage
46
{
5-
public interface IBrowserStorage
6-
{
7-
ValueTask SetAsync(StorageScope scope, string key, string value);
8-
ValueTask<string?> GetAsync(StorageScope scope, string key);
9-
ValueTask RemoveAsync(StorageScope scope, string key);
10-
ValueTask<bool> ExistsAsync(StorageScope scope, string key);
11-
}
7+
ValueTask SetAsync(StorageScope scope, string key, string value);
8+
ValueTask<string?> GetAsync(StorageScope scope, string key);
9+
ValueTask RemoveAsync(StorageScope scope, string key);
10+
ValueTask<bool> ExistsAsync(StorageScope scope, string key);
1211
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
namespace CodeBeam.UltimateAuth.Client.Abstractions
1+
namespace CodeBeam.UltimateAuth.Client.Abstractions;
2+
3+
public interface ISessionCoordinator : IAsyncDisposable
24
{
3-
public interface ISessionCoordinator : IAsyncDisposable
4-
{
5-
/// <summary>
6-
/// Starts session coordination.
7-
/// Should be idempotent.
8-
/// </summary>
9-
Task StartAsync(CancellationToken cancellationToken = default);
5+
/// <summary>
6+
/// Starts session coordination.
7+
/// Should be idempotent.
8+
/// </summary>
9+
Task StartAsync(CancellationToken cancellationToken = default);
1010

11-
/// <summary>
12-
/// Stops coordination (optional).
13-
/// </summary>
14-
Task StopAsync();
11+
/// <summary>
12+
/// Stops coordination (optional).
13+
/// </summary>
14+
Task StopAsync();
1515

16-
event Action? ReauthRequired;
17-
}
16+
event Action? ReauthRequired;
1817
}

src/CodeBeam.UltimateAuth.Client/Authentication/DefaultUAuthStateManager.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
namespace CodeBeam.UltimateAuth.Client.Authentication
1+
namespace CodeBeam.UltimateAuth.Client.Authentication;
2+
3+
/// <summary>
4+
/// Orchestrates the lifecycle of UAuthState.
5+
/// This is the single authority responsible for keeping
6+
/// client-side authentication state in sync with the server.
7+
/// </summary>
8+
public interface IUAuthStateManager
29
{
310
/// <summary>
4-
/// Orchestrates the lifecycle of UAuthState.
5-
/// This is the single authority responsible for keeping
6-
/// client-side authentication state in sync with the server.
11+
/// Current in-memory authentication state.
712
/// </summary>
8-
public interface IUAuthStateManager
9-
{
10-
/// <summary>
11-
/// Current in-memory authentication state.
12-
/// </summary>
13-
UAuthState State { get; }
13+
UAuthState State { get; }
1414

15-
/// <summary>
16-
/// Ensures the authentication state is valid.
17-
/// May call server validate/refresh if needed.
18-
/// </summary>
19-
Task EnsureAsync(CancellationToken ct = default);
15+
/// <summary>
16+
/// Ensures the authentication state is valid.
17+
/// May call server validate/refresh if needed.
18+
/// </summary>
19+
Task EnsureAsync(CancellationToken ct = default);
2020

21-
/// <summary>
22-
/// Called after a successful login.
23-
/// </summary>
24-
Task OnLoginAsync();
21+
/// <summary>
22+
/// Called after a successful login.
23+
/// </summary>
24+
Task OnLoginAsync();
2525

26-
/// <summary>
27-
/// Called after logout.
28-
/// </summary>
29-
Task OnLogoutAsync();
26+
/// <summary>
27+
/// Called after logout.
28+
/// </summary>
29+
Task OnLogoutAsync();
3030

31-
/// <summary>
32-
/// Forces state to be cleared and re-validation required.
33-
/// </summary>
34-
void MarkStale();
35-
}
31+
/// <summary>
32+
/// Forces state to be cleared and re-validation required.
33+
/// </summary>
34+
void MarkStale();
3635
}
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
using CodeBeam.UltimateAuth.Client.Abstractions;
2-
using Microsoft.AspNetCore.Components.Authorization;
3-
using System.Security.Principal;
1+
using Microsoft.AspNetCore.Components.Authorization;
42

5-
namespace CodeBeam.UltimateAuth.Client.Authentication
6-
{
7-
internal sealed class UAuthAuthenticationStateProvider : AuthenticationStateProvider
8-
{
9-
private readonly IUAuthStateManager _stateManager;
3+
namespace CodeBeam.UltimateAuth.Client.Authentication;
104

11-
public UAuthAuthenticationStateProvider(IUAuthStateManager stateManager)
12-
{
13-
_stateManager = stateManager;
14-
_stateManager.State.Changed += _ => NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
15-
}
5+
internal sealed class UAuthAuthenticationStateProvider : AuthenticationStateProvider
6+
{
7+
private readonly IUAuthStateManager _stateManager;
168

17-
public override Task<AuthenticationState> GetAuthenticationStateAsync()
18-
{
19-
var principal = _stateManager.State.ToClaimsPrincipal();
20-
return Task.FromResult(new AuthenticationState(principal));
21-
}
9+
public UAuthAuthenticationStateProvider(IUAuthStateManager stateManager)
10+
{
11+
_stateManager = stateManager;
12+
_stateManager.State.Changed += _ => NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
13+
}
2214

15+
public override Task<AuthenticationState> GetAuthenticationStateAsync()
16+
{
17+
var principal = _stateManager.State.ToClaimsPrincipal();
18+
return Task.FromResult(new AuthenticationState(principal));
2319
}
20+
2421
}

0 commit comments

Comments
 (0)