Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected override async Task OnParametersSetAsync()
return;
}

_state = await HubFlowReader.GetStateAsync(new HubSessionId(HubKey));
if (!HubSessionId.TryParse(HubKey, out var hubSessionId))
_state = await HubFlowReader.GetStateAsync(hubSessionId);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand Down Expand Up @@ -74,7 +75,10 @@ private async Task ProgrammaticPkceLogin()
if (hub is null)
return;

var credentials = await HubCredentialResolver.ResolveAsync(new HubSessionId(HubKey));
if (!HubSessionId.TryParse(HubKey, out var hubSessionId))
return;

var credentials = await HubCredentialResolver.ResolveAsync(hubSessionId);

var request = new PkceLoginRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CodeBeam.UltimateAuth.Core.Abstractions;
using CodeBeam.UltimateAuth.Core.Domain;
using CodeBeam.UltimateAuth.Core.MultiTenancy;
using CodeBeam.UltimateAuth.Core.Options;
using CodeBeam.UltimateAuth.Server.Options;
using CodeBeam.UltimateAuth.Server.Stores;
Expand Down Expand Up @@ -41,7 +42,7 @@ public async Task<IActionResult> BeginLogin(
hubSessionId: hubSessionId,
flowType: HubFlowType.Login,
clientProfile: client_profile,
tenantId: null,
tenant: TenantKeys.System,
returnUrl: return_url,
payload: payload,
expiresAt: _clock.UtcNow.Add(_options.Hub.FlowLifetime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<MudText>UAuthState @(StateManager.State.IsAuthenticated == true ? "Authenticated" : "Not Authenticated") - UserId:@(StateManager.State.UserKey)</MudText>
<AuthorizeView>
<Authorized>
<MudText>Authorized context is shown. @context.User.Identity.IsAuthenticated</MudText>
<MudText>Authorized context is shown. @context?.User?.Identity?.IsAuthenticated</MudText>
</Authorized>
<NotAuthorized>
<MudText>Not Authorized context is shown.</MudText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CodeBeam.UltimateAuth.Core.Domain;
using CodeBeam.UltimateAuth.Core.Extensions;
using CodeBeam.UltimateAuth.Core.Infrastructure;
using CodeBeam.UltimateAuth.Core.MultiTenancy;
using CodeBeam.UltimateAuth.Credentials;
using CodeBeam.UltimateAuth.Credentials.InMemory.Extensions;
using CodeBeam.UltimateAuth.Credentials.Reference;
Expand Down Expand Up @@ -112,13 +113,9 @@
app.MapOpenApi();
app.MapScalarApiReference();
using var scope = app.Services.CreateScope();
//scope.ServiceProvider.GetRequiredService<IUserLifecycleStore>();
//scope.ServiceProvider.GetRequiredService<IUserProfileStore>();
//scope.ServiceProvider.GetRequiredService<IUserIdentifierStore>();
//scope.ServiceProvider.GetRequiredService<ICredentialStore<UserKey>>();
var seedRunner = scope.ServiceProvider.GetRequiredService<SeedRunner>();

await seedRunner.RunAsync(tenantId: null);
await seedRunner.RunAsync(null);
}

app.UseHttpsRedirection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm.Pages
public partial class Home
{
[CascadingParameter]
public UAuthState Auth { get; set; }
public UAuthState Auth { get; set; } = null!;

private string? _username;
private string? _password;
Expand Down
15 changes: 7 additions & 8 deletions src/CodeBeam.UltimateAuth.Client/Abstractions/IBrowserStorage.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using CodeBeam.UltimateAuth.Client.Contracts;

namespace CodeBeam.UltimateAuth.Client.Utilities
namespace CodeBeam.UltimateAuth.Client.Utilities;

public interface IBrowserStorage
{
public interface IBrowserStorage
{
ValueTask SetAsync(StorageScope scope, string key, string value);
ValueTask<string?> GetAsync(StorageScope scope, string key);
ValueTask RemoveAsync(StorageScope scope, string key);
ValueTask<bool> ExistsAsync(StorageScope scope, string key);
}
ValueTask SetAsync(StorageScope scope, string key, string value);
ValueTask<string?> GetAsync(StorageScope scope, string key);
ValueTask RemoveAsync(StorageScope scope, string key);
ValueTask<bool> ExistsAsync(StorageScope scope, string key);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
namespace CodeBeam.UltimateAuth.Client.Abstractions
namespace CodeBeam.UltimateAuth.Client.Abstractions;

public interface ISessionCoordinator : IAsyncDisposable
{
public interface ISessionCoordinator : IAsyncDisposable
{
/// <summary>
/// Starts session coordination.
/// Should be idempotent.
/// </summary>
Task StartAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Starts session coordination.
/// Should be idempotent.
/// </summary>
Task StartAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Stops coordination (optional).
/// </summary>
Task StopAsync();
/// <summary>
/// Stops coordination (optional).
/// </summary>
Task StopAsync();

event Action? ReauthRequired;
}
event Action? ReauthRequired;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
namespace CodeBeam.UltimateAuth.Client.Authentication
namespace CodeBeam.UltimateAuth.Client.Authentication;

/// <summary>
/// Orchestrates the lifecycle of UAuthState.
/// This is the single authority responsible for keeping
/// client-side authentication state in sync with the server.
/// </summary>
public interface IUAuthStateManager
{
/// <summary>
/// Orchestrates the lifecycle of UAuthState.
/// This is the single authority responsible for keeping
/// client-side authentication state in sync with the server.
/// Current in-memory authentication state.
/// </summary>
public interface IUAuthStateManager
{
/// <summary>
/// Current in-memory authentication state.
/// </summary>
UAuthState State { get; }
UAuthState State { get; }

/// <summary>
/// Ensures the authentication state is valid.
/// May call server validate/refresh if needed.
/// </summary>
Task EnsureAsync(CancellationToken ct = default);
/// <summary>
/// Ensures the authentication state is valid.
/// May call server validate/refresh if needed.
/// </summary>
Task EnsureAsync(CancellationToken ct = default);

/// <summary>
/// Called after a successful login.
/// </summary>
Task OnLoginAsync();
/// <summary>
/// Called after a successful login.
/// </summary>
Task OnLoginAsync();

/// <summary>
/// Called after logout.
/// </summary>
Task OnLogoutAsync();
/// <summary>
/// Called after logout.
/// </summary>
Task OnLogoutAsync();

/// <summary>
/// Forces state to be cleared and re-validation required.
/// </summary>
void MarkStale();
}
/// <summary>
/// Forces state to be cleared and re-validation required.
/// </summary>
void MarkStale();
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using CodeBeam.UltimateAuth.Client.Abstractions;
using Microsoft.AspNetCore.Components.Authorization;
using System.Security.Principal;
using Microsoft.AspNetCore.Components.Authorization;

namespace CodeBeam.UltimateAuth.Client.Authentication
{
internal sealed class UAuthAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly IUAuthStateManager _stateManager;
namespace CodeBeam.UltimateAuth.Client.Authentication;

public UAuthAuthenticationStateProvider(IUAuthStateManager stateManager)
{
_stateManager = stateManager;
_stateManager.State.Changed += _ => NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
}
internal sealed class UAuthAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly IUAuthStateManager _stateManager;

public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
var principal = _stateManager.State.ToClaimsPrincipal();
return Task.FromResult(new AuthenticationState(principal));
}
public UAuthAuthenticationStateProvider(IUAuthStateManager stateManager)
{
_stateManager = stateManager;
_stateManager.State.Changed += _ => NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
}

public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
var principal = _stateManager.State.ToClaimsPrincipal();
return Task.FromResult(new AuthenticationState(principal));
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using Microsoft.AspNetCore.Components;

namespace CodeBeam.UltimateAuth.Client.Authentication
namespace CodeBeam.UltimateAuth.Client.Authentication;

internal sealed class UAuthCascadingStateProvider : CascadingValueSource<UAuthState>, IDisposable
{
internal sealed class UAuthCascadingStateProvider : CascadingValueSource<UAuthState>, IDisposable
{
private readonly IUAuthStateManager _stateManager;
private readonly IUAuthStateManager _stateManager;

public UAuthCascadingStateProvider(IUAuthStateManager stateManager)
: base(() => stateManager.State, isFixed: false)
{
_stateManager = stateManager;
_stateManager.State.Changed += OnStateChanged;
}
public UAuthCascadingStateProvider(IUAuthStateManager stateManager)
: base(() => stateManager.State, isFixed: false)
{
_stateManager = stateManager;
_stateManager.State.Changed += OnStateChanged;
}

private void OnStateChanged(UAuthStateChangeReason _)
{
NotifyChangedAsync();
}
private void OnStateChanged(UAuthStateChangeReason _)
{
NotifyChangedAsync();
}

public void Dispose()
{
_stateManager.State.Changed -= OnStateChanged;
}
public void Dispose()
{
_stateManager.State.Changed -= OnStateChanged;
}
}
Loading