Skip to content

Strawman for new authorization packages that can be shared between server and client #9997

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

Closed
wants to merge 8 commits into from

Conversation

SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented May 6, 2019

Our goal is that the same authorization attributes, DI services, and classes should be usable both in server-side ASP.NET Core (without any changes to customer code) and in client-side Blazor.

To make that possible, we have to introduce at least one new package where we can put things that should be common to both server and client. Restrictions include:

  • Package must be netstandard2.0
  • Package must be shipped both in the shared framework and as a NuGet package
  • Cannot reference APIs that only make sense on the server such as Http.Abstractions (or HttpContext in particular)

This PR moves the majority of classes out of Microsoft.AspNetCore.Authorization and puts them in a new package, Microsoft.AspNetCore.Authorization.Common. I'm not in any way in love with that name. I'm happy to call it anything else if someone has a preference. It just has to mean "authorization things that work both on the server and on the client".

This shouldn't be a breaking change, since Microsoft.AspNetCore.Authorization now references the .Common package, so all existing types continue to work (if you rebuild your app). I haven't set up actual type forwarders for people who reference things using reflection. Not sure if we would do that. I also haven't moved any tests since this is just a draft.

Similarly I created Microsoft.AspNetCore.Authorization.Common.Abstractions to hold the two interfaces we need that used to be in Http.Abstractions.

I haven't built anything end-to-end with this yet so don't even know if it meets our needs. Currently this is just seeking feedback on (a) the whole idea of moving all these things around, and (b) the package naming.

@SteveSandersonMS SteveSandersonMS requested review from HaoK and rynowak May 6, 2019 15:25
@SteveSandersonMS SteveSandersonMS added this to the 3.0.0-preview6 milestone May 6, 2019
@SteveSandersonMS SteveSandersonMS added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components labels May 6, 2019

namespace Microsoft.AspNetCore.Authorization.Policy
{
public class CommonPolicyEvaluator : ICommonPolicyEvaluator
Copy link
Member

@HaoK HaoK May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need a PolicyEvaluator in the common layer? It was only introduced to tie authN + authZ together, I thought on the client side there's no authentication needed, so wouldn't the base IAuthorizationService be sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do want to evaluate policies in client-side code.

I thought on the client side there's no authentication needed

That's not correct. Although authentication isn't enforced there (all true enforcement is server-side), we still want policies to exist as a way of informing the client about what the user is going to be allowed to do.

@HaoK
Copy link
Member

HaoK commented May 6, 2019

We seem to use Core everywhere, maybe Authorization.Core instead?

@SteveSandersonMS
Copy link
Member Author

Since this is probably superseded by #10021, I'll leave it alone for now. Once #10021 is merged, this can probably just be closed.

@SteveSandersonMS
Copy link
Member Author

Superseded by #10021.

@dougbu dougbu deleted the stevesa/add-authorization-common branch May 18, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants