Skip to content

Commit e00e06a

Browse files
committed
UAuthState Implementation
1 parent 0386e0f commit e00e06a

File tree

30 files changed

+474
-197
lines changed

30 files changed

+474
-197
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<meta charset="utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<base href="/" />
8-
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
98
<link rel="stylesheet" href="app.css" />
109
<link rel="stylesheet" href="UltimateAuth.BlazorServer.styles.css" />
1110
<link rel="icon" type="image/png" href="favicon.png" />

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@using CodeBeam.UltimateAuth.Server.Cookies
1010
@using CodeBeam.UltimateAuth.Server.Infrastructure
1111
@using CodeBeam.UltimateAuth.Server.Services
12+
@inject IUAuthStateManager StateManager
1213
@inject IUAuthFlowService<UserId> Flow
1314
@inject ISnackbar Snackbar
1415
@inject ISessionQueryService<UserId> SessionQuery
@@ -52,9 +53,10 @@
5253
<MudStack Spacing="0">
5354
<MudText>State of Authentication:</MudText>
5455
<MudText>@(_authState?.User?.Identity?.IsAuthenticated == true ? "Authenticated" : "Not Authenticated") - UserId:@(_authState?.User?.Identity?.Name)</MudText>
56+
<MudText>UAuthState @(StateManager.State.IsAuthenticated == true ? "Authenticated" : "Not Authenticated") - UserId:@(StateManager.State.UserId)</MudText>
5557
<AuthorizeView>
5658
<Authorized>
57-
<MudText>Authorized context is shown.</MudText>
59+
<MudText>Authorized context is shown. @context.User.Identity.IsAuthenticated</MudText>
5860
</Authorized>
5961
<NotAuthorized>
6062
<MudText>Not Authorized context is shown.</MudText>

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ public partial class Home
1717
protected override async Task OnInitializedAsync()
1818
{
1919
Diagnostics.Changed += OnDiagnosticsChanged;
20-
_authState = await AuthStateProvider.GetAuthenticationStateAsync();
20+
}
21+
22+
protected override async Task OnAfterRenderAsync(bool firstRender)
23+
{
24+
if (firstRender)
25+
{
26+
await StateManager.EnsureAsync();
27+
_authState = await AuthStateProvider.GetAuthenticationStateAsync();
28+
StateHasChanged();
29+
}
2130
}
2231

2332
private void OnDiagnosticsChanged()
@@ -33,6 +42,8 @@ private async Task ProgrammaticLogin()
3342
Secret = "Password!",
3443
};
3544
await UAuthClient.LoginAsync(request);
45+
await UAuthClient.ValidateAsync();
46+
await StateManager.EnsureAsync();
3647
_authState = await AuthStateProvider.GetAuthenticationStateAsync();
3748
}
3849

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using CodeBeam.UltimateAuth.Client.Authentication;
21
using CodeBeam.UltimateAuth.Client.Extensions;
32
using CodeBeam.UltimateAuth.Core.Domain;
43
using CodeBeam.UltimateAuth.Core.Extensions;
@@ -37,14 +36,6 @@
3736

3837
builder.Services.AddAuthorization();
3938

40-
builder.Services.AddHttpContextAccessor();
41-
42-
builder.Services.AddScoped<IUAuthAuthenticationStateSource, ServerAuthStateSource>();
43-
//builder.Services.AddScoped<UAuthBlazorServerAuthenticationStateProvider>();
44-
45-
//builder.Services.AddScoped<AuthenticationStateProvider>(sp =>
46-
// sp.GetRequiredService<UAuthBlazorServerAuthenticationStateProvider>());
47-
4839
builder.Services.AddUltimateAuth();
4940

5041
builder.Services.AddUltimateAuthServer(o => {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@page "/"
22
@page "/login"
3+
@using CodeBeam.UltimateAuth.Client.Authentication
34
@using CodeBeam.UltimateAuth.Client.Diagnostics
45
@using CodeBeam.UltimateAuth.Core.Runtime
6+
@inject IUAuthStateManager StateManager
57
@inject IHttpClientFactory HttpClientFactory
68
@inject IUAuthProductInfoProvider ProductInfo
79
@inject ISnackbar Snackbar

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ protected override async Task OnInitializedAsync()
2020
_authState = await AuthStateProvider.GetAuthenticationStateAsync();
2121
}
2222

23+
protected override async Task OnAfterRenderAsync(bool firstRender)
24+
{
25+
if (firstRender)
26+
{
27+
await StateManager.EnsureAsync();
28+
_authState = await AuthStateProvider.GetAuthenticationStateAsync();
29+
StateHasChanged();
30+
}
31+
}
32+
2333
private void OnDiagnosticsChanged()
2434
{
2535
InvokeAsync(StateHasChanged);

samples/blazor-standalone-wasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
o.Endpoints.Authority = "https://localhost:6110";
2121
});
2222

23-
builder.Services.AddScoped<AuthenticationStateProvider, UAuthAuthenticationStateProvider>();
24-
builder.Services.AddScoped<IUAuthAuthenticationStateSource, ClientAuthStateSource>();
23+
//builder.Services.AddScoped<AuthenticationStateProvider, UAuthAuthenticationStateProvider>();
24+
//builder.Services.AddScoped<IUAuthAuthenticationStateSource, ClientAuthStateSource>();
2525

2626
builder.Services.AddAuthorizationCore();
2727

samples/blazor-standalone-wasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm/wwwroot/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>UltimateAuth.Sample.BlazorStandaloneWasm</title>
88
<base href="/" />
9-
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
109
<link rel="stylesheet" href="css/app.css" />
1110
<link rel="icon" type="image/png" href="favicon.png" />
1211
<link href="UltimateAuth.Sample.BlazorStandaloneWasm.styles.css" rel="stylesheet" />

src/CodeBeam.UltimateAuth.Client/Abstractions/IClientAuthState.cs

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

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

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

0 commit comments

Comments
 (0)