-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Update Identity Components in Blazor project template #51134
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
Conversation
- Move "/Logout" endpoint - Make App.razor more consistent between modes
cdc96b0
to
425bd12
Compare
Hi @halter73. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
@halter73 took a look at the changes. Overall looks good, the main questions that I have are:
|
There was earlier discussion about this in the PR that originally added the Identity components to the project template when I added it the old way without I think [CascadingParameter]
public required HttpContext HttpContext { get; set; } looks a lot nicer than [CascadingParameter]
public HttpContext HttpContext { get; set; } = default!; And we even got some community agreement. Although they also noted that this goes directly against our guidance:
@MackinnonBuck also brought up a good point about how it could prevent code-generated parameter setting from working in the future if we ever decided to do that. We're only using I'm fine with whatever we decide. We're still using
The
Here's the discussion from when you suggested it in the original PR. @SteveSandersonMS mentioined:
It was actually less than 15 places, but it was pretty close. I agree there is a lot of repetition, but there are also quite a few very simple components like Lockout.razor that gain nothing from a base component. I'm not sure I buy that a base class is all that constraining. If people have their own base component, couldn't they make Identity base component inherit from their own? But I do think avoiding inheritance where possible is generally a good idea because it shows there's nothing up our sleeves so to speak. All of the services and parameters we use, we declare directly on the page. |
...plates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Pages/Manage/Email.razor
Outdated
Show resolved
Hide resolved
} | ||
|
||
var result = await UserManager.ResetPasswordAsync(user, Input.Code, Input.Password); | ||
if (result.Succeeded) | ||
{ | ||
RedirectManager.RedirectTo("/Account/ResetPasswordConfirmation"); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of subtle that RedirectTo()
never returns, making the return
statement redundant. From reading the code, it might be hard to tell at first that each of these if
statements acts as a kind of implicit guard clause. But I don't feel a strong way about this so if you think it's fine to remove the return
s then I won't fight it! 🙂
e3a6a88
to
13a8e2c
Compare
- This avoids making HasCallerSpecifiedRenderMode true in the @rendermode="null" case
Hi @halter73. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
- There's no good place for it currently when it's referenced by the client project This reverts commit fac57d1.
You can review the project's generated with these template changes at https://github.com/halter73/BlazorWebTemplateMatrix#readme. You can just install the latest 8.0 SDK from the https://github.com/dotnet/installers repo (8.0.100-rtm.23506.1 currently) and reference that in the |
@JeremyLikness @halter73 Are we sure we want to use "auth" in the template? The problem with "auth" is that it's an abbreviation for both authentication & authorization, which makes it ambiguous and it's also pretty informal. Some alternatives:
|
navigationManager.NavigateTo(uri); | ||
throw new InvalidOperationException($"{nameof(IdentityRedirectManager)} must be called from the server."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but in wasm/server navigationManager.NavigateTo(uri);
continues executing, which is a visible behavior difference. /cc: @SteveSandersonMS
@halter73 I do not care much about the base class vs non base class, it's unlikely impossible for anyone to have a base class that is broadly used and where everything on the base class is used by every derived implementation, it's always a trade-off of convenience vs repetition. The other main thing is the |
- Add tests for "--interactivity WebAssembly" - Add tests for "--interactivity Auto" - Add tests for "--all-interactive" - Add tests for "--empty" - Add tests for "--auth Individual" - Add tests for "--use-local-db" - Update="Data\app.db" - Fix reference to dotnet-ef.dll in PrepareForTest.targets
Hi @Kumima. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
I routinely put an _Imports.razor at the root of my projects with @Attribute [Authorize] to enforce authorization on all pages, but because @Attribute [AllowAnonymous] is not explicitly defined on the razor pages in Pages/Account that ends up breaking the pages and requires me to go specify it manually. |
Hi @los93sol. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Description
This PR addresses a large amount of feedback from #50722 which was merged before they could all be addressed to unblock Accessibility Testing effort. The primary impacts are:
Runtime changes
AddComponentRenderMode
'srenderMode
param nullable to support disabling interactivity on a per-page basis with the help of@rendermode="null"
(effectively).Template changes
using
inProgram.cs
when the individual auth option is selected with no interactivity.--all-interactive
) instead of just per-page interactivity to the new Identity components.DatabaseErrorPage
by callingUseMigrationsEndPoint()
when necessary.IEmailSender<ApplicationUser>
API instead ofIEmailSender
for easier customization of emails.IHttpContextAccessor
from the template because that is generally regarded as bad practice due to the unnecessary reliance onAsyncLocal
._
) from private field names.null!
anddefault!
.<button>
for logout link in nav bar rather than<a onclick="document.getElementById('logout-form').submit();">
, and remove separateLogoutForm.razor
.Customer Impact
This fixes several bugs in the Blazor project template when choosing the individual auth option and makes several runtime fixes that will be beneficial to any global interactive Blazor application that needs to include some components that must always be statically rendered.
Regression?
Risk
Obviously, we would rather not make such a large change after RC2. Particularly when it's a change that touches public API. Fortunately, the runtime changes are very small, and only to parts of the runtime that were last updated in RC2 (see #50181 and #50946).
The vast majority of the changes in the PR only affect the Blazor project template when the non-default individual auth option is selected. This was merged very late in RC2 (#50722) with the expectation that we would make major changes prior to GA.
Verification
Packaging changes reviewed?