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

Not authorize tag helper addition #76

Open
mute503 opened this issue Mar 15, 2019 · 1 comment
Open

Not authorize tag helper addition #76

mute503 opened this issue Mar 15, 2019 · 1 comment

Comments

@mute503
Copy link

mute503 commented Mar 15, 2019

For the authorize tag helpers, a typical case that I didn't see covered would be needing to show one section of html to authorized users and show a different section of html to non-authorized users. Maybe something like a asp-authorize-anonymous.

I didn't see a way of doing this with current tag helpers but it could be useful and effectively eliminate if-elses in razor based on user being logged in.

@dpaquette
Copy link
Owner

dpaquette commented Mar 21, 2019

This is actually a pretty common scenario but I'm not sure how best to solve for it. I am open to suggestions.
Here are a couple options I am kicking around:

Introducing an authorize tag

<authorize asp-policy="somePolicy">
  <authorized> <div> this will only be rendered if the user is authorized </div> </authorized>
  <not-authorized> <div> this will only be rendered if the user is not authorized </div> </not-authorized>
</authorize>

This one is a little verbose but should be pretty clear what is happening.

Introducing an asp-not-authorize attribute

<div asp-authorize asp-policy="somePolicy"> this will only be rendered if the user is authorized </div> 
<div asp-not-authorize asp-policy="somePolicy"> this will only be rendered if the user is not authorized </div> 

This one is less verbose than the first option but it would require the policy to be evaluated twice which seems like a bad idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants