-
Notifications
You must be signed in to change notification settings - Fork 10.3k
AuthorizeView should expose the results of the AuthorizeAsync call as a context variable. #43959
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
Comments
@michac thanks for contacting us. Your ask sounds reasonable, but I'll let other people on the team chime in. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@michac feel free to send us a PR with the fix. We'd be happy to consider it. |
Looks like the simplest change that could work would be in AuthorizeViewCore.cs to replace the Then in
Finally, around line 99, we replace the Obviously we would need to adjust the tests accordingly, but this seems like a relatively safe and simple change if the addition of the argument to the NotAuthorized fragment won't break things... I simply don't know that... This path doesn't change any public exposure except that if we would also want to expose the authorization result for others via a new property |
A trial implementation of this reveals that Invoke can only take one argument, so I guess we do need to introduce a wrapping object or modify the declaration of the NotAuthorized fragment. This means that we would have some breaking changes to the people providing the |
The changing of the NotAuthorized argument would break so much, it looks like the only reasonable path is to just expose the AuthorizationResult directly on AuthorizeViewCore.cs which likely isn't actually very useful. |
Can the AuthorizedViewCore have more than one |
(Just as an aside, this issue is a more general version of #44162, which was probably rather too specific.) I've had a go at adding this feature to the framework source, because A) I would like to use it and B) it saddens me that so much good information in As @IDisposable discovered above, the challenge in implementing this is not really preserving the AuthorizationResult, it's passing it onto the I tried/considered a few things:
Anyway, I implemented the last one. It didn't break any tests and was easy to add one new test for. But I don't know if this sort of approach (passing an object by its base class even though it's always a derived type) is considered to be a disgusting hack unworthy of a PR, and for that I would need some MS input. I hesitate to tag @mkArtakMSFT but you did mark it "help candidate" - can you connect us with someone who could opine on the most acceptable approach here? |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I am using asp.net Policy to enforce licensing restrictions. When a user is not authorized to view or use a component I want to be able to tell them why they are not authorized. This is supported via Policy, where you can include a reason why access is denied that then shows up in the AuthorizationResult as a AuthorizationFailureReason. AuthorizeViewCore, however, throws away all this metadata and boils the result down to a true/false for which view to show.
Describe the solution you'd like
I wrote a custom AuthorizeViewCore that wraps the AuthenticationState and the AuthorizationResult in a new type, and makes that available as a context variable. Now my NotAuthorized view can show a tooltip or other message indicating why it's not authorized (ex. "this is disabled because you are not licensed for this feature").
Additional context
No response
The text was updated successfully, but these errors were encountered: