Skip to content
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

Role-based authorization not working correctly when using Blazor WebView in MAUI App #24874

Closed
efonsecab opened this issue Sep 23, 2024 · 6 comments
Assignees
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working

Comments

@efonsecab
Copy link

Description

I have a MAUI Blazor Hybrid App which uses Role-Base authorization.
The authorization works, and roles are correctly read by the CustomAuthenticationStateProvider.
Problem is the AuthorizeRouteView is never refreshing as expected, items requiring authorization are never shown.
I tried a force reload approach, however, there seems to be a bug related to reload:
microsoft/fluentui-blazor#1036 (comment)

dotnet/aspnetcore#52119

Here is part of my code:
https://github.com/pticostaricags/FairPlayCombined/blob/development/src/FairPlayCombinedSln/FairPlayTube.MAUI/MauiProgram.cs

https://github.com/pticostaricags/FairPlayCombined/blob/development/src/FairPlayCombinedSln/FairPlayTube.MAUI/Components/Pages/Login.razor

https://github.com/pticostaricags/FairPlayCombined/blob/development/src/FairPlayCombinedSln/FairPlayTube.MAUI/Components/Layout/MainLayout.razor

Is there any solution or workaround for this behavior so I can make the authorization flow work as expected.

Steps to Reproduce

  1. Create a MAUI Blazor Hybrid App
  2. Create an authorization API
  3. Perform role-based authorization from the Blazor pages inside the MAUI App

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.1.24453.9

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No workaround found yet.

Relevant log output

No response

@efonsecab efonsecab added the t/bug Something isn't working label Sep 23, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@samhouts samhouts added potential-regression This issue described a possible regression on a currently supported version., verification pending area-blazor Blazor Hybrid / Desktop, BlazorWebView labels Sep 23, 2024
@mkArtakMSFT mkArtakMSFT added this to the .NET 9.0 GA milestone Sep 23, 2024
@halter73
Copy link
Member

Problem is the AuthorizeRouteView is never refreshing as expected

I noticed that your CustomAuthenticationStateProvider doesn't implement AuthenticationStateChanged. How are you expecting AuthorizeRouteView to "refresh"? If the initial AuthenticationState needs to be refreshed, don't you need to signal the change?

Yes, this used to work in .NET MAUI

Did this work in a MAUI Blazor Hybrid App before? If so, can you please provide a minimal repro pinpointing the behavior that changed between versions and instructions on how to build and run the app in a way that demonstrates the regression between .NET 8 and .NET 9?

https://github.com/pticostaricags/FairPlayCombined/tree/development/src/FairPlayCombinedSln/FairPlayTube.MAUI isn't exactly minimal.

@efonsecab
Copy link
Author

Problem is the AuthorizeRouteView is never refreshing as expected

I noticed that your CustomAuthenticationStateProvider doesn't implement AuthenticationStateChanged. How are you expecting AuthorizeRouteView to "refresh"? If the initial AuthenticationState needs to be refreshed, don't you need to signal the change?

Yes, this used to work in .NET MAUI

Did this work in a MAUI Blazor Hybrid App before? If so, can you please provide a minimal repro pinpointing the behavior that changed between versions and instructions on how to build and run the app in a way that demonstrates the regression between .NET 8 and .NET 9?

https://github.com/pticostaricags/FairPlayCombined/tree/development/src/FairPlayCombinedSln/FairPlayTube.MAUI isn't exactly minimal.

It used to work in another application before, with the same approach, with no need of using the event:
image

@halter73
Copy link
Member

halter73 commented Sep 23, 2024

Can you provide a single-project repro that clearly demonstrates what breaks after updating from .NET 8 (or whatever version it used to work in) to .NET 9 that's as minimal as you can make it? It should be published to its own repository on GitHub with a commit pointing to the working code just before the upgrade and another commit after the upgrade to .NET 9 where it breaks.

The custom AuthenticationStateProvider shouldn't involve any secrets, clients, or anything like that. You can construct hard-coded ClaimsPrincipals for the purpose of the repro since the details about how a custom AuthenticationStateProvider creates its AuthenticationState is irrelevant to the framework.

@halter73 halter73 added the s/needs-repro Attach a solution or code which reproduces the issue label Sep 23, 2024
@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Sep 23, 2024
@halter73 halter73 added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look labels Sep 24, 2024
Copy link
Contributor

Hi @efonsecab. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Sep 30, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@dotnet-policy-service dotnet-policy-service bot removed this from the .NET 9.0 GA milestone Oct 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants