forked from easyquery/DotNetSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: upgrade EqDemo.BlazorWasm.AdhocReporting to .NET 8.0 #21
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
6
commits into
master
Choose a base branch
from
upgrade/blazor-wasm-adhocreporting-to-net8
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
6 commits
Select commit
Hold shift + click to select a range
f0dfe1a
chore: upgrade EqDemo.BlazorWasm.AdhocReporting to .NET 8.0
devin-ai-integration[bot] c21770d
fix: migrate client-side auth from OIDC/IdentityServer to cookie-base…
devin-ai-integration[bot] 3afadc4
fix: use NavigationManager for logout to avoid anti-forgery token issue
devin-ai-integration[bot] ca13fd9
fix: use forceLoad navigation for all Identity links to bypass Blazor…
devin-ai-integration[bot] c94c8f6
fix: use relative paths for returnUrl to avoid LocalRedirect exception
devin-ai-integration[bot] 9d09561
fix: remove IAccessTokenProviderAccessor from Reports.razor and unuse…
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
12 changes: 6 additions & 6 deletions
12
...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
22 changes: 20 additions & 2 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,25 @@ | ||
| @page "/authentication/{action}" | ||
| @using Microsoft.AspNetCore.Components.WebAssembly.Authentication | ||
| <RemoteAuthenticatorView Action="@Action" /> | ||
|
|
||
| @inject NavigationManager Navigation | ||
|
|
||
| @code{ | ||
| [Parameter] public string? Action { get; set; } | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| var returnUrl = Uri.EscapeDataString("/"); | ||
| var redirectUrl = Action?.ToLower() switch | ||
| { | ||
| "login" => $"Identity/Account/Login?returnUrl={returnUrl}", | ||
| "register" => $"Identity/Account/Register?returnUrl={returnUrl}", | ||
| "logout" => "Identity/Account/LogOut", | ||
| "profile" => "Identity/Account/Manage", | ||
| _ => "" | ||
| }; | ||
|
|
||
| if (!string.IsNullOrEmpty(redirectUrl)) | ||
| { | ||
| Navigation.NavigateTo(redirectUrl, 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
54 changes: 54 additions & 0 deletions
54
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Client/ServerAuthenticationStateProvider.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,54 @@ | ||
| using System.Net.Http.Json; | ||
| using System.Security.Claims; | ||
| using Microsoft.AspNetCore.Components.Authorization; | ||
|
|
||
| namespace EqDemo.Client; | ||
|
|
||
| public class ServerAuthenticationStateProvider : AuthenticationStateProvider | ||
| { | ||
| private readonly HttpClient _httpClient; | ||
|
|
||
| public ServerAuthenticationStateProvider(HttpClient httpClient) | ||
| { | ||
| _httpClient = httpClient; | ||
| } | ||
|
|
||
| public override async Task<AuthenticationState> GetAuthenticationStateAsync() | ||
| { | ||
| try | ||
| { | ||
| var userInfo = await _httpClient.GetFromJsonAsync<UserInfo>("api/user"); | ||
| if (userInfo != null && userInfo.IsAuthenticated) | ||
| { | ||
| var claims = new List<Claim> | ||
| { | ||
| new Claim(ClaimTypes.Name, userInfo.UserName ?? string.Empty) | ||
| }; | ||
|
|
||
| if (userInfo.Roles != null) | ||
| { | ||
| foreach (var role in userInfo.Roles) | ||
| { | ||
| claims.Add(new Claim(ClaimTypes.Role, role)); | ||
| } | ||
| } | ||
|
|
||
| var identity = new ClaimsIdentity(claims, "serverauth"); | ||
| return new AuthenticationState(new ClaimsPrincipal(identity)); | ||
| } | ||
| } | ||
| catch (Exception) | ||
| { | ||
| // Not authenticated or server unavailable | ||
| } | ||
|
|
||
| return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())); | ||
| } | ||
|
|
||
| public class UserInfo | ||
| { | ||
| public bool IsAuthenticated { get; set; } | ||
| public string? UserName { get; set; } | ||
| public List<string>? Roles { get; set; } | ||
| } | ||
| } |
29 changes: 21 additions & 8 deletions
29
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,37 @@ | ||
| @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> | ||
| <span>Hello, @context.User.Identity?.Name!</span> | ||
| <button class="nav-link btn btn-link" @onclick="NavigateToManage">Manage</button> | ||
| <button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button> | ||
| </Authorized> | ||
| <NotAuthorized> | ||
| <a href="authentication/register">Register</a> | ||
| <a href="authentication/login">Log in</a> | ||
| <button class="nav-link btn btn-link" @onclick="NavigateToRegister">Register</button> | ||
| <button class="nav-link btn btn-link" @onclick="NavigateToLogin">Log in</button> | ||
| </NotAuthorized> | ||
| </AuthorizeView> | ||
|
|
||
| @code{ | ||
| private async Task BeginSignOut(MouseEventArgs args) | ||
| private void NavigateToManage() | ||
| { | ||
| await SignOutManager.SetSignOutState(); | ||
| Navigation.NavigateTo("authentication/logout"); | ||
| Navigation.NavigateTo("Identity/Account/Manage", forceLoad: true); | ||
| } | ||
|
|
||
| private void NavigateToRegister() | ||
| { | ||
| Navigation.NavigateTo("Identity/Account/Register", forceLoad: true); | ||
| } | ||
|
|
||
| private void NavigateToLogin() | ||
| { | ||
| Navigation.NavigateTo("Identity/Account/Login", forceLoad: true); | ||
| } | ||
|
|
||
| private void BeginSignOut() | ||
| { | ||
| Navigation.NavigateTo("Identity/Account/LogOut", 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
25 changes: 0 additions & 25 deletions
25
...etCore/Blazor/AdHocReporting.BlazorWasm/Server/Controllers/OidcConfigurationController.cs
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
AspNetCore/Blazor/AdHocReporting.BlazorWasm/Server/Controllers/UserController.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,26 @@ | ||
| using System.Security.Claims; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace EqDemo.Controllers | ||
| { | ||
| [Route("api/[controller]")] | ||
| [ApiController] | ||
| public class UserController : ControllerBase | ||
| { | ||
| [HttpGet] | ||
| public IActionResult GetCurrentUser() | ||
| { | ||
| if (User.Identity?.IsAuthenticated == true) | ||
| { | ||
| return Ok(new | ||
| { | ||
| IsAuthenticated = true, | ||
| UserName = User.Identity.Name, | ||
| Roles = User.FindAll(ClaimTypes.Role).Select(c => c.Value).ToList() | ||
| }); | ||
| } | ||
|
|
||
| return Ok(new { IsAuthenticated = false }); | ||
| } | ||
| } | ||
| } |
10 changes: 3 additions & 7 deletions
10
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
Oops, something went wrong.
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.