Skip to content

Integrate AuthorizeView with actual authorization #10487

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

Merged
merged 6 commits into from
May 24, 2019

Conversation

SteveSandersonMS
Copy link
Member

No description provided.

@SteveSandersonMS SteveSandersonMS added the area-blazor Includes: Blazor, Razor Components label May 23, 2019
@SteveSandersonMS SteveSandersonMS added this to the 3.0.0-preview6 milestone May 23, 2019

namespace Microsoft.AspNetCore.Blazor.Services
{
internal class WebAssemblyConsoleLogger<T> : ILogger<T>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is intended as a minimal way of meeting the requirements for the built-in default IAuthorizationService, without bringing in the full-fledged Microsoft.AspNetCore.Extensions.Logging.

The full logging package adds about 100KB to the app size and a couple extra assembly downloads, so if we can have a bare-bones one without it that's preferable. People who want to use the full thing (e.g., to control logging levels, have multiple categories, etc.) can still reference it and add it to their DI config.

Copy link
Member

Choose a reason for hiding this comment

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

The full logging package adds about 100KB to the app size and a couple extra assembly downloads, so if we can have a bare-bones one without it that's preferable. People who want to use the full thing (e.g., to control logging levels, have multiple categories, etc.) can still reference it and add it to their DI config.

To me this seems like a great thing to chase down in the future when we have a TFM for web assembly. Right now if we wanted to offer a thinner profile of these features for Blazor we have no real way to do so.

@@ -102,6 +104,10 @@ private void CreateServiceProvider()
};
});

// Needed for authorization
services.AddOptions();
services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(WebAssemblyConsoleLogger<>)));
Copy link
Member

Choose a reason for hiding this comment

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

I think you'll also have to support ILoggerFactory. You're going to find code in our stack that expects that, and it should be easy to add.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know it is fairly easy to add, but we don't have any code paths that hit it currently, and I'm trying to be minimal with this. We're always free to add more default services later.

If you have reasons to think it's going to be problematic if we don't, let me know, otherwise I'll leave this as-is.

Copy link
Member

Choose a reason for hiding this comment

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

I can't really articulate a specific scenario. This just feels lazy - because we know what we would do if people complain. We could prevent them from having to log and issue and wait for us to fix it by just doing a little thing now.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we want to have a similar set of services in both environments, otherwise when I try to use a component that does logging, then I end up having to register it myself, making the experience different in the two environments.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've added a super-minimal ILoggerFactory.

Yeah, we want to have a similar set of services in both environments

I'd be cautious about thinking about it like that. The environments have very different capabilities, goals, and characteristics. Most of the server-side services are for server-side application-server concerns, so a large proportion of them won't be present on WebAssembly by design.

var policy = await AuthorizationPolicy.CombineAsync(
AuthorizationPolicyProvider, selfAsAuthorizeData);
var result = await AuthorizationService.AuthorizeAsync(user, Resource, policy);
return result.Succeeded;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same as what DefaultHubDispatcher does, which looks more or less equivalent in terms of its requirements and its position in the stack.

Copy link
Member

Choose a reason for hiding this comment

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

So just to confirm I'm reading this correctly, selfAsAuthorizeData is total set of authorize attributes for this view that you want to use for the authZ check.

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 (except this info doesn’t come from attributes in this case- that’s a separate feature on the Blazor router).

@@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Authorization" />
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a better idea right now, but are we really OK with baking this in at the lowest level. We're saying all components present and future have access to the ASP.NET Authorization library

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking about things like a React native experience, and I think the point is that you'd still want access to things like AuthorizeView in that environment. So I don't really feel like it's a problem I guess. ....

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I agree with both the uneasiness and the conclusion that this is the best outcome currently.

Considering that all the Components/Blazor packages have AspNetCore in their name, it doesn't really change anything to reference Microsoft.AspNetCore.Authorization as compared with if we had Microsoft.AspNetCore.Components.Authorization.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this makes me a bit sad on the inside. I'm wondering if we could use some of the infrastructure for single file publish coming in 3.0 to separate the core of the platform from the baked-in components that we give you into two assemblies and simply ILMerge them at publish time.

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

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

:shipit: from me. it would be good if @HaoK can look as well.

@SteveSandersonMS
Copy link
Member Author

TODO Manual ref-assembly code for the new params on AuthorizeView

Copy link
Member

@HaoK HaoK left a comment

Choose a reason for hiding this comment

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

This looks pretty reasonable

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Looked at the changes, they seem fine except for a couple of comments. Still have to look at the tests

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/blazor-authorization branch from f14a3f0 to f63cdce Compare May 24, 2019 11:20
@SteveSandersonMS SteveSandersonMS merged commit d18a033 into master May 24, 2019
@ghost ghost deleted the stevesa/blazor-authorization branch May 24, 2019 14:28
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants