Repository navigation
Add Identity Components to Blazor template - #50722
Conversation
| <EditForm Model="Input" FormName="forgot-password" OnValidSubmit="OnValidSubmitAsync" method="post"> | ||
| <DataAnnotationsValidator /> | ||
| <ValidationSummary class="text-danger" role="alert" /> | ||
|
|
||
| <div class="form-floating mb-3"> | ||
| <InputText id="email" @bind-Value="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="[email protected]" /> | ||
| <label for="email" class="form-label">Email</label> | ||
| <ValidationMessage For="() => Input.Email" class="text-danger" /> | ||
| </div> | ||
| <button type="submit" class="w-100 btn btn-lg btn-primary">Reset password</button> | ||
| </EditForm> |
There was a problem hiding this comment.
@SteveSandersonMS do we want some Enhanced magic here?
There was a problem hiding this comment.
Longer term maybe. For now I'd go with whatever's been tested.
|
Note to reviewers: There are a lot of changes sitting in halter73/BlazorWebIdentity#2 that will eventually get merged into this PR. |
surayya-MS
left a comment
There was a problem hiding this comment.
I only found 2 accessibility problems
29f691c to
ead9757
Compare
439b06c to
2af81a0
Compare
| @foreach (var provider in _otherLogins) | ||
| { | ||
| <button | ||
| id="[email protected]" |
There was a problem hiding this comment.
Here and everywhere else
| <button class="btn btn-primary" type="submit">Download</button> | ||
| </form> | ||
| <p> | ||
| <a id="delete" href="/Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a> |
There was a problem hiding this comment.
| <a id="delete" href="/Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a> | |
| <a id="delete" href="Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a> |
| <p> | ||
| <strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong> | ||
| </p> | ||
| <form id="download-data" action="/Account/Manage/DownloadPersonalData" method="post"> |
There was a problem hiding this comment.
| <form id="download-data" action="/Account/Manage/DownloadPersonalData" method="post"> | |
| <form id="download-data" action="Account/Manage/DownloadPersonalData" method="post"> |
| @code { | ||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| _ = await UserAccessor.GetRequiredUserAsync(); |
There was a problem hiding this comment.
Why discard this task?
There was a problem hiding this comment.
It's discarding the result, but still awaiting the task.
There was a problem hiding this comment.
Oh yeah. Strange but yes I see.
| /// <summary> | ||
| /// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
| /// directly from your code. This API may change or be removed in future releases. | ||
| /// </summary> |
There was a problem hiding this comment.
I don't get how people are supposed to interpret this remark. How can they not use it "directly from their code"? This is literally in their code already.
Can it be phrased in a more realistic way? For example, "Do not rename or remove this parameter because it is relied on by [some external thing]"?
There was a problem hiding this comment.
I think we could probably make all these private anyway and not have to worry about customers seeing this in intellisense?
| var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); | ||
| code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); | ||
| var callbackUrl = NavigationManager.GetUriWithQueryParameters( | ||
| NavigationManager.ToAbsoluteUri("/Account/ConfirmEmail").AbsoluteUri, |
There was a problem hiding this comment.
| NavigationManager.ToAbsoluteUri("/Account/ConfirmEmail").AbsoluteUri, | |
| NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, |
or at least I would expect so
| var user = await UserManager.FindByEmailAsync(Email); | ||
| if (user == null) | ||
| { | ||
| // Need a way to trigger a 404 from Blazor: https://github.com/dotnet/aspnetcore/issues/45654 |
There was a problem hiding this comment.
| // Need a way to trigger a 404 from Blazor: https://github.com/dotnet/aspnetcore/issues/45654 |
If you can set the status code on HttpContext then that would be good to do. But even if not, we shouldn't have a comment like this in the template.
|
|
||
| <h1>Reset password confirmation</h1> | ||
| <p> | ||
| Your password has been reset. Please <a href="/Account/Login">click here to log in</a>. |
There was a problem hiding this comment.
| Your password has been reset. Please <a href="/Account/Login">click here to log in</a>. | |
| Your password has been reset. Please <a href="Account/Login">click here to log in</a>. |
| // [3] NavigateTo() does not throw an exception, meaning we're not rendering from an endpoint, so we throw | ||
| // an InvalidOperationException to indicate that we can't redirect. | ||
| navigationManager.NavigateTo(uri); | ||
| throw new InvalidOperationException($"Can only redirect when rendering from an endpoint."); |
There was a problem hiding this comment.
Why do you need to do this? If you're trying to account for interactive rendering too, would it meet your needs to change line 33 to use NavigateTo(uri, force: true)?
| }; | ||
|
|
||
| [DoesNotReturn] | ||
| public void RedirectTo(string uri) |
There was a problem hiding this comment.
There's a lot of code that passes in root-relative URLs (e.g., /Account/Blah). Can you confirm those will be handled correctly even if there's a nonempty pathbase? I'm not certain that's accounted for in the logic here, but may be wrong!
|
|
||
| var redirectUrl = UriHelper.BuildRelative( | ||
| context.Request.PathBase, | ||
| $"/Account/ExternalLogin", |
There was a problem hiding this comment.
| $"/Account/ExternalLogin", | |
| "/Account/ExternalLogin", |
|
|
||
| namespace BlazorWeb_CSharp.Identity; | ||
|
|
||
| public class IdentityRevalidatingAuthenticationStateProvider : RevalidatingServerAuthenticationStateProvider |
There was a problem hiding this comment.
Would be good to add a comment block above this class to indicate the basic ideas about what it does.
|
|
||
| namespace BlazorWeb_CSharp.Identity; | ||
|
|
||
| public class PersistingRevalidatingAuthenticationStateProvider : RevalidatingServerAuthenticationStateProvider |
There was a problem hiding this comment.
Would be good to add a comment block above this class to indicate the basic ideas about what it does.
|
Wow, security is hard! Can we just document that users have to not be evil? |
SteveSandersonMS
left a comment
There was a problem hiding this comment.
There are a lot of review comments, some of which do need to be addressed for correctness (e.g., all the root-relative URLs). In a lot of cases I stopped posting repeated comments of the same point, so if you see a general pattern of comments, please assume it applies to the entire PR and not only the specific lines I posted about.
I'm approving now on the basis that you'll make good choices about which of the feedback to address, and I won't be around later today to check.
However, could you try to get a ack from @javiercn before merging too? I know he's spent some time looking at this and may have been thinking more deeply about the actual security content. My focus has been on how understandable/idiomatic the content is.
|
Merging this as is. We've identified a limitation here that we will be researching some more and will document it as a known issue in RC2 and will then address in the GA milestone. |
commented
Sep 25, 2023
|
@SteveSandersonMS @MackinnonBuck
I agree it looks better than having |
commented
Sep 25, 2023
|
Hi @iphdav. 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. |
Add Identity Components to Blazor template
Description
This adds the option to add Identity Razor Components (
*.razorfiles) when using the Blazor project template. This supports the same feature set as the Identity Razor Pages (*.cshtmlfiles). We've already done an accessibility pass over these newly added components and this PR includes all the fixes for Accessibility too. As with the Identity Razor Pages, this supports local authentication (with the option to configure external login providers) and Identity management using EF Core.Fixes #48786
Customer Impact
These Identity Razor Components have been a common request for years as noted above, because it allows Blazor developers to use Identity without needing to add Razor Pages infrastructure which would otherwise be unnecessary and doesn't integrate well with the rest of the app. For example, the Identity Razor Pages to a Blazor app would use a different layout that doesn't match the look and feel of the Razor Components that make up the rest of the app.
Regression?
Risk
These are template only changes that only affect the brand new Blazor project template. It should have no impact on the project template output unless you opt-in to the individual auth option (other than a small fix to make the
--emptyoption produce compileable output with allInteractivityPlatformoptions.)Verification
We're also adding new validation scenarios for vendors to validate periodically.
Packaging changes reviewed?
@MackinnonBuck @SteveSandersonMS @javiercn @surayya-MS