forked from easyquery/DotNetSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade AdHocReporting.BlazorWasm (Server/Client/Shared) to .NET 8 #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
5
commits into
master
Choose a base branch
from
devin/1777991077-net8-blazorwasm-adhoc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b9a39cd
Upgrade AdHocReporting.BlazorWasm (Server/Client/Shared) to .NET 8
devin-ai-integration[bot] f47ef14
Address Devin Review: register custom AuthenticationStateProvider and…
devin-ai-integration[bot] 692e6d0
Address Devin Review: replace logout POST form in LoginDisplay with l…
devin-ai-integration[bot] 85ef9a4
Address Devin Review: route auth links through authentication/{action…
devin-ai-integration[bot] 9602509
Address Devin Review: ensure role claims land in the auth cookie
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
...re/Blazor/AdHocReporting.BlazorWasm/Client/EqDemo.BlazorWasm.AdhocReporting.Client.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Client/HostAuthenticationStateProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using System.Net; | ||
| using System.Net.Http.Json; | ||
| using System.Security.Claims; | ||
|
|
||
| using Microsoft.AspNetCore.Components.Authorization; | ||
|
|
||
| namespace EqDemo.Client; | ||
|
|
||
| /// <summary> | ||
| /// Resolves the current user's authentication state by calling a small endpoint | ||
| /// on the server (which authenticates the request via the ASP.NET Core Identity | ||
| /// auth cookie). Replaces the OIDC-based remote authentication state provider | ||
| /// that came with Microsoft.AspNetCore.ApiAuthorization.IdentityServer. | ||
| /// </summary> | ||
| public sealed class HostAuthenticationStateProvider : AuthenticationStateProvider | ||
| { | ||
| private const string AuthenticationType = "Cookies"; | ||
|
|
||
| private static readonly AuthenticationState Anonymous = | ||
| new(new ClaimsPrincipal(new ClaimsIdentity())); | ||
|
|
||
| private readonly HttpClient _http; | ||
|
|
||
| public HostAuthenticationStateProvider(HttpClient http) | ||
| { | ||
| _http = http; | ||
| } | ||
|
|
||
| public override async Task<AuthenticationState> GetAuthenticationStateAsync() | ||
| { | ||
| try | ||
| { | ||
| var response = await _http.GetAsync("_auth/me"); | ||
| if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) | ||
| { | ||
| return Anonymous; | ||
| } | ||
|
|
||
| response.EnsureSuccessStatusCode(); | ||
|
|
||
| var info = await response.Content.ReadFromJsonAsync<AuthInfo>(); | ||
| if (info is null || !info.IsAuthenticated) | ||
| { | ||
| return Anonymous; | ||
| } | ||
|
|
||
| var claims = (info.Claims ?? Array.Empty<AuthClaim>()) | ||
| .Select(c => new Claim(c.Type, c.Value)); | ||
| var identity = new ClaimsIdentity(claims, AuthenticationType, ClaimTypes.Name, ClaimTypes.Role); | ||
| return new AuthenticationState(new ClaimsPrincipal(identity)); | ||
| } | ||
| catch (HttpRequestException) | ||
| { | ||
| return Anonymous; | ||
| } | ||
| } | ||
|
|
||
| private sealed record AuthInfo(bool IsAuthenticated, AuthClaim[]? Claims); | ||
|
|
||
| private sealed record AuthClaim(string Type, string Value); | ||
| } |
22 changes: 19 additions & 3 deletions
22
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Client/Pages/Authentication.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,23 @@ | ||
| @page "/authentication/{action}" | ||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
| <RemoteAuthenticatorView Action="@Action" /> | ||
| @inject NavigationManager Navigation | ||
|
|
||
| @code{ | ||
| @code { | ||
| [Parameter] public string? Action { get; set; } | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| // The legacy OIDC client-side authentication flow has been replaced with | ||
| // server-side cookie auth via ASP.NET Core Identity Razor Pages. Redirect | ||
| // legacy /authentication/{action} URLs to the new endpoints. | ||
| var target = Action switch | ||
| { | ||
| "login" => "Identity/Account/Login", | ||
| "register" => "Identity/Account/Register", | ||
| "logout" => "Identity/Account/Logout", | ||
| "profile" => "Identity/Account/Manage", | ||
| _ => "/" | ||
| }; | ||
|
|
||
| Navigation.NavigateTo(target, forceLoad: true); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 1 addition & 13 deletions
14
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Client/Shared/LoginDisplay.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,12 @@ | ||
| @using Microsoft.AspNetCore.Components.Authorization | ||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
|
|
||
| @inject NavigationManager Navigation | ||
| @inject SignOutSessionStateManager SignOutManager | ||
|
|
||
| <AuthorizeView> | ||
| <Authorized> | ||
| <a href="authentication/profile">Hello, @context.User.Identity?.Name!</a> | ||
| <button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button> | ||
| <a href="authentication/logout" class="nav-link btn btn-link">Log out</a> | ||
| </Authorized> | ||
| <NotAuthorized> | ||
| <a href="authentication/register">Register</a> | ||
| <a href="authentication/login">Log in</a> | ||
| </NotAuthorized> | ||
| </AuthorizeView> | ||
|
|
||
| @code{ | ||
| private async Task BeginSignOut(MouseEventArgs args) | ||
| { | ||
| await SignOutManager.SetSignOutState(); | ||
| Navigation.NavigateTo("authentication/logout"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...etCore/Blazor/AdHocReporting.BlazorWasm/Server/Controllers/OidcConfigurationController.cs
This file was deleted.
Oops, something went wrong.
11 changes: 3 additions & 8 deletions
11
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Server/Data/AppDbContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...re/Blazor/AdHocReporting.BlazorWasm/Shared/EqDemo.BlazorWasm.AdhocReporting.Shared.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.