Skip to content

Commit ecd2800

Browse files
committed
Client Blazor Tests 3
1 parent 26e1118 commit ecd2800

9 files changed

Lines changed: 2717 additions & 2 deletions

File tree

‎src/client/CodeBeam.UltimateAuth.Client.Blazor/Components/UAuthApp.razor.cs‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,111 @@
33

44
namespace CodeBeam.UltimateAuth.Client.Blazor;
55

6+
/// <summary>
7+
/// Provides the root Blazor integration component for UltimateAuth.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>
11+
/// <see cref="UAuthApp"/> initializes the UltimateAuth client runtime,
12+
/// exposes the current <see cref="UAuthState"/> as a cascading value,
13+
/// coordinates the authenticated session lifecycle, and optionally provides
14+
/// the application's Blazor router.
15+
/// </para>
16+
/// <para>
17+
/// Applications using UltimateAuth Blazor components should normally place
18+
/// their application content within this component.
19+
/// </para>
20+
/// <para>
21+
/// Client-side authentication state is intended for UI behavior only and
22+
/// does not constitute a security boundary. Authorization of protected
23+
/// resources must always be enforced by the server.
24+
/// </para>
25+
/// </remarks>
626
public partial class UAuthApp
727
{
828
private bool _initialized;
929
private bool _coordinatorStarted;
1030

31+
/// <summary>
32+
/// Gets or sets the application content rendered within the UltimateAuth context.
33+
/// </summary>
1134
[Parameter]
1235
public RenderFragment? ChildContent { get; set; }
1336

37+
/// <summary>
38+
/// Gets or sets the content rendered by the built-in router when the current user is not authorized to access a route.
39+
/// </summary>
40+
/// <remarks>
41+
/// This parameter is used only when <see cref="UseBuiltInRouter"/> is enabled.
42+
/// </remarks>
1443
[Parameter]
1544
public RenderFragment? NotAuthorized { get; set; }
1645

46+
/// <summary>
47+
/// Gets or sets whether <see cref="UAuthApp"/> should provide the application's Blazor router.
48+
/// </summary>
49+
/// <remarks>
50+
/// Set this to <see langword="false"/> when the application provides its own router.
51+
/// </remarks>
1752
[Parameter]
1853
public bool UseBuiltInRouter { get; set; }
1954

55+
/// <summary>
56+
/// Gets or sets whether UltimateAuth client routes are included in the assemblies searched by the built-in router.
57+
/// </summary>
58+
/// <remarks>
59+
/// The default value is <see langword="true"/>.
60+
/// </remarks>
2061
[Parameter]
2162
public bool UseUAuthClientRoutes { get; set; } = true;
2263

64+
/// <summary>
65+
/// Gets or sets the assembly containing the application's routable components.
66+
/// </summary>
67+
/// <remarks>
68+
/// This value is used by the built-in router.
69+
/// </remarks>
2370
[Parameter]
2471
public Assembly? AppAssembly { get; set; }
2572

73+
/// <summary>
74+
/// Gets or sets additional assemblies that should be searched for routable components.
75+
/// </summary>
76+
/// <remarks>
77+
/// When <see cref="UseUAuthClientRoutes"/> is enabled, the UltimateAuth
78+
/// Blazor client assemblies are added to this set automatically.
79+
/// </remarks>
2680
[Parameter]
2781
public IEnumerable<Assembly>? AdditionalAssemblies { get; set; }
2882

83+
/// <summary>
84+
/// Gets or sets the default layout used by the built-in
85+
/// <see cref="Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView"/>.
86+
/// </summary>
2987
[Parameter]
3088
public Type? DefaultLayout { get; set; }
3189

90+
/// <summary>
91+
/// Gets or sets the CSS selector used by Blazor's focus-on-navigation behavior.
92+
/// </summary>
93+
/// <remarks>
94+
/// The default value is <c>h1</c>.
95+
/// </remarks>
3296
[Parameter]
3397
public string? FocusSelector { get; set; } = "h1";
3498

99+
/// <summary>
100+
/// Gets or sets how UltimateAuth state changes affect component rendering.
101+
/// </summary>
102+
/// <remarks>
103+
/// The default value is <see cref="UAuthRenderMode.Manual"/>.
104+
/// </remarks>
35105
[Parameter]
36106
public UAuthRenderMode RenderMode { get; set; } = UAuthRenderMode.Manual;
37107

108+
/// <summary>
109+
/// Gets or sets the callback invoked when the session coordinator determines that reauthentication is required.
110+
/// </summary>
38111
[Parameter]
39112
public EventCallback OnReauthRequired { get; set; }
40113

@@ -81,6 +154,7 @@ private void OnStateChanged(UAuthStateChangeReason reason)
81154
_ = InvokeAsync(async () =>
82155
{
83156
await Coordinator.StartAsync();
157+
_coordinatorStarted = true;
84158
});
85159
}
86160

‎src/client/CodeBeam.UltimateAuth.Client.Blazor/Components/UAuthLoginForm.razor.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ private string ResolvedEndpoint
286286

287287
if (_credentials != null && EffectiveHubSessionId is not null)
288288
{
289-
query.Add($"hub={EffectiveHubSessionId}");
289+
query.Add(
290+
$"{UAuthConstants.Query.Hub}=" +
291+
$"{Uri.EscapeDataString(EffectiveHubSessionId.Value.Value)}");
290292
}
291293

292294
if (!string.IsNullOrWhiteSpace(returnUrl))

‎src/client/CodeBeam.UltimateAuth.Client.Blazor/Components/UAuthStateView.razor.cs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ private async Task<bool> EvaluateAuthorizationAsync()
111111
if (!AuthState.IsAuthenticated)
112112
return false;
113113

114+
var hasRoles = _rolesParsed.Count > 0;
115+
var hasPermissions = _permissionsParsed.Count > 0;
116+
var hasPolicy = !string.IsNullOrWhiteSpace(Policy);
117+
118+
// No explicit authorization requirements:
119+
// authentication itself is sufficient.
120+
if (!hasRoles && !hasPermissions && !hasPolicy)
121+
return true;
122+
114123
var roleResults = _rolesParsed
115124
.Select(AuthState.IsInRole)
116125
.ToList();
@@ -223,6 +232,6 @@ private async Task<bool> EvaluatePolicyAsync()
223232

224233
private string BuildAuthKey()
225234
{
226-
return $"{Roles}|{Permissions}|{Policy}|{MatchMode}";
235+
return $"{Roles}|{Permissions}|{Policy}|{MatchMode}{RequireActive}";
227236
}
228237
}

‎src/client/CodeBeam.UltimateAuth.Client.Blazor/Infrastructure/UAuthRequestClient.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public async Task<UAuthTransportResult> SendJsonAsync(string endpoint, object? p
9191

9292
public async Task<TTryResult> TryAndCommitAsync<TTryResult>(string tryEndpoint, string commitEndpoint, object request, CancellationToken ct = default)
9393
{
94+
ct.ThrowIfCancellationRequested();
95+
9496
await _bootstrapper.EnsureStartedAsync();
9597

9698
var response = await _js.InvokeAsync<TTryResult>(

0 commit comments

Comments
 (0)