-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix AuthorizeViewCore.cs invalid rendering logic #31794
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
Fixes #24381 Component render would occur between lines 95 and 96 if the AuthenticationState Task had already been completed before it was awaited on line 95. https://github.com/dotnet/aspnetcore/blob/d70439cc82253ac32cc3eaf94ce965bab1ac9d37/src/Components/Authorization/src/AuthorizeViewCore.cs#L73-97 That leads to rendering of NotAuthorized state in BuildRenderTree function which is unexpected behaviour. NotAuthorized state should only ever be rendered after IsAuthorizedAsync has been completed. https://github.com/dotnet/aspnetcore/blob/d70439cc82253ac32cc3eaf94ce965bab1ac9d37/src/Components/Authorization/src/AuthorizeViewCore.cs#L53-70 If the AuthenticationState had not been completed before it was awaited the rendering would have occurred before line 95 and no render would occur between lines 95 and 96. In that case the AuthorizeViewCore works as expected. In this fix the isAuthorized field is made nullable and it is used to determine the state to display in the BuildRenderTree function. Until the authorization has completed the isAuthorized is null the Authorizing state is displayed as expected.
|
Thanks for the PR @juho-hanhimaki do you think you could add a test to https://github.com/dotnet/aspnetcore/blob/d70439cc82253ac32cc3eaf94ce965bab1ac9d37/src/Components/Authorization/test/AuthorizeViewTest.cs to verify the new behavior? |
|
@HaoK I'll take a look at adding the test. Took some effort to get the thing building locally. |
|
I added the test that covers the PR/issue. Because the |
|
Awesome that test looks great, on last small thing, can you confirm locally that without your changes your test fails |
|
@HaoK I did, and the test fails as it should without the changes to |
|
Thanks for doing this work @juho-hanhimaki ! |
|
Thank you too for taking the PR! |
|
Hi @juho-hanhimaki. 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. |


Component render would occur between lines 95 and 96 if the AuthenticationState task had already been completed before it was awaited on line 95.
aspnetcore/src/Components/Authorization/src/AuthorizeViewCore.cs
Lines 73 to 97 in d70439c
That leads to rendering of NotAuthorized state in BuildRenderTree function which is unexpected behaviour (currentAuthenticationState is set but authorization is still in progress). NotAuthorized state should only ever be rendered after IsAuthorizedAsync has been completed.
aspnetcore/src/Components/Authorization/src/AuthorizeViewCore.cs
Lines 53 to 70 in d70439c
If the AuthenticationState had not been completed before it was awaited the rendering would have occurred before line 95 and no render would occur between lines 95 and 96. In that case the AuthorizeViewCore works as expected.
In this fix the isAuthorized field is made nullable and it is used to determine the state to display in the BuildRenderTree function. Until the authorization has completed the isAuthorized is null the Authorizing state is displayed as expected.
Addresses #24381