Skip to content

Flow endpoint and httpcontext always from authz middleware #22672

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 5 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public async Task Invoke(HttpContext context)
return;
}

// Note that the resource will be null if there is no matched endpoint
var authorizeResult = await policyEvaluator.AuthorizeAsync(policy, authenticateResult, context, resource: endpoint);
var authorizeResult = await policyEvaluator.AuthorizeAsync(policy, authenticateResult, context, resource: context);

var authorizationMiddlewareResultHandler = context.RequestServices.GetRequiredService<IAuthorizationMiddlewareResultHandler>();
await authorizationMiddlewareResultHandler.HandleAsync(_next, context, policy, authorizeResult);
Expand Down
10 changes: 6 additions & 4 deletions src/Security/Authorization/test/AuthorizationMiddlewareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ public async Task Invoke_SingleValidClaimShouldSucceed()
}

[Fact]
public async Task AuthZResourceShouldBeEndpoint()
public async Task AuthZResourceShouldBeHttpContextAndHaveHEndpoint()
{
// Arrange
object resource = null;
HttpContext resource = null;
var policy = new AuthorizationPolicyBuilder().RequireAssertion(c =>
{
resource = c.Resource;
resource = c.Resource as HttpContext;
return true;
}).Build();
var policyProvider = new Mock<IAuthorizationPolicyProvider>();
Expand All @@ -335,7 +335,9 @@ public async Task AuthZResourceShouldBeEndpoint()
await middleware.Invoke(context);

// Assert
Assert.Equal(endpoint, resource);
Assert.NotNull(resource);
Assert.Equal(context, resource);
Assert.Equal(endpoint, resource.GetEndpoint());
}

[Fact]
Expand Down