-
Notifications
You must be signed in to change notification settings - Fork 447
Conversation
@BrennanConroy, |
samples/ChatSample/Hubs/Chat.cs
Outdated
{ | ||
Context.Connection.Dispose(); | ||
} | ||
//if (!Context.User.Identity.IsAuthenticated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
samples/ChatSample/Startup.cs
Outdated
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ChatSample | ||
{ | ||
public class req : IAuthorizationRequirement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this class name
samples/ChatSample/Startup.cs
Outdated
public class req : IAuthorizationRequirement | ||
{ | ||
} | ||
public class reqHandler : AuthorizationHandler<req> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one too
samples/ChatSample/Startup.cs
Outdated
@@ -54,8 +71,13 @@ public void ConfigureServices(IServiceCollection services) | |||
services.AddTransient<ISmsSender, AuthMessageSender>(); | |||
|
|||
services.AddSignalR(); | |||
services.AddEndPoint<HubEndPoint<Chat>>(options => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line here?
using Microsoft.Extensions.Primitives; | ||
using Microsoft.Extensions.Internal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Sort this last using
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far. Bring @HaoK in to look at the authentication process. We're trying to mimic MVC here, but with EndPoints instead of Controllers/Actions as the authorized resource.
{ | ||
public class EndPointOptions<TEndPoint> where TEndPoint : EndPoint | ||
{ | ||
public AuthorizationPolicy Policy { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to take the actual policy or a name to look up? I know AuthorizeAttribute
uses a name, but then again it has to because it's an Attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to take the name, as that would enable scenarios where the policy is resolved dynamically by name which would be blocked if you took the policy instance always.
@@ -48,6 +58,59 @@ public HttpConnectionDispatcher(ConnectionManager manager, ILoggerFactory logger | |||
} | |||
} | |||
|
|||
private async Task<bool> AuthorizeAsync<TEndPoint>(HttpContext context) where TEndPoint : EndPoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this pretty much an exact copy of the AuthorizeFilter logic? As apart of Auth 2.0 I'll try to consolidate this logic somewhere that MVC + SignalR can consume rather than duplicate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its from AuthorizeFilter, a common spot for this would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @javiercn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. We should have live somewhere where both MVC and Signal R can consume
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So currently AuthZ doesn't depend on HttpAbstractions, assuming we want to keep that clean, we will need to add a new package for this helper in Security... maybe Microsoft.AspNetCore.Authorization.Http?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is this more appropriate as a shared common code i.e. AuthorizationHelper similar to SecurityHelper (or we could just add this as a new method in SecurityHelper too)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make a package like Microsoft.AspNetCore.Authentication.Policy and I would offer a service
IPolicyAuthenticationProvider {
Task AuthenticateAsync(HttpContext context, string policyName);
}
It's implementation will do what the AuthorizeFilter does before setting the principal into the context. This has two benefits:
- You can reuse this logic across implementations (MVC, SignalR, any other middleware).
- You can get access to a principal that matches exactly what that policy defines at any point where you have access to the HttpContext.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I'll start a prototype/design PR for the rough shape of something this week
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like aspnet/Security#1148 look reasonable? It basically splits things into the authentication method, and authorization method (eventually this might have logic to distinguish between challenge/forbidden)
faa3930
to
c1f3845
Compare
@BrennanConroy What's the deal with this PR? |
f6bea88
to
c86a3b4
Compare
@BrennanConroy rebsae |
@@ -51,6 +60,58 @@ public HttpConnectionDispatcher(ConnectionManager manager, ILoggerFactory logger | |||
} | |||
} | |||
|
|||
private async Task<bool> AuthorizeAsync<TEndPoint>(HttpContext context) where TEndPoint : EndPoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this code to a helper
c86a3b4
to
842662e
Compare
🆙 📅 |
private Task<bool> AuthorizeAsync<TEndPoint>(HttpContext context) where TEndPoint : EndPoint | ||
{ | ||
// TODO: Authorize attribute on EndPoint | ||
var options = context.RequestServices.GetRequiredService<IOptions<EndPointOptions<TEndPoint>>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you resolving options twice?
f28baa3
to
23ca2a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small notes and approval is subject to build passing
var options = context.RequestServices.GetRequiredService<IOptions<EndPointOptions<TEndPoint>>>().Value; | ||
// TODO: Authorize attribute on EndPoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a bug for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
public static class AuthorizeHelper | ||
{ | ||
public static async Task<bool> AuthorizeAsync(HttpContext context, AuthorizationPolicy policy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we complete synchronously if policy
is null
, perhaps this is a place for ValueTask<bool>
? C# 7 lets you drop it in place and continue using async
. It's not a super high-performance code path, but it seems useful for the relatively common case of not having an auth policy.
@davidfowl thoughts on more ValueTask
s? Premature optimization? Other unknown costs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it in a follow up commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's going to be a new commit to remove the jasmine crap, may as well throw it in here, it's a small change (unless ValueTask isn't available in our current package set, then I agree, just get it in).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, Task<bool>
is cached: https://referencesource.microsoft.com/#mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs,a431f9d7dd423518
@@ -0,0 +1,152 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be checked in? If not, can we gitignore it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It totally confused me.
4f9c8e5
to
8f9f6bc
Compare
This PR is mainly to see what the current Auth progress is and if it is heading in the right direction and also to get input on design. Built on top of #240. Try to ignore most of the weird stuff in the samples.
@moozzyk @davidfowl @anurse @mikaelm12