This repository was archived by the owner on Dec 13, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
src/Microsoft.AspNetCore.Authorization.Policy Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 33
44using System ;
55using Microsoft . AspNetCore . Authorization ;
6+ using Microsoft . Extensions . Options ;
67
78namespace Microsoft . AspNetCore . Builder
89{
@@ -17,5 +18,20 @@ public static IApplicationBuilder UseAuthorization(this IApplicationBuilder app)
1718
1819 return app . UseMiddleware < AuthorizationMiddleware > ( ) ;
1920 }
21+
22+ public static IApplicationBuilder UseAuthorization ( this IApplicationBuilder app , AuthorizationOptions options )
23+ {
24+ if ( app == null )
25+ {
26+ throw new ArgumentNullException ( nameof ( app ) ) ;
27+ }
28+
29+ if ( options == null )
30+ {
31+ throw new ArgumentNullException ( nameof ( options ) ) ;
32+ }
33+
34+ return app . UseMiddleware < AuthorizationMiddleware > ( new DefaultAuthorizationPolicyProvider ( Options . Create ( options ) ) ) ;
35+ }
2036 }
2137}
Original file line number Diff line number Diff line change @@ -40,8 +40,6 @@ public async Task Invoke(HttpContext context)
4040 throw new ArgumentNullException ( nameof ( context ) ) ;
4141 }
4242
43- var policyEvaluator = context . RequestServices . GetRequiredService < IPolicyEvaluator > ( ) ;
44-
4543 var endpoint = context . Features . Get < IEndpointFeature > ( ) ? . Endpoint ;
4644 var authorizeData = endpoint ? . Metadata . GetOrderedMetadata < IAuthorizeData > ( ) ?? Array . Empty < IAuthorizeData > ( ) ;
4745 var policy = await AuthorizationPolicy . CombineAsync ( _policyProvider , authorizeData ) ;
@@ -51,6 +49,8 @@ public async Task Invoke(HttpContext context)
5149 return ;
5250 }
5351
52+ var policyEvaluator = context . RequestServices . GetRequiredService < IPolicyEvaluator > ( ) ;
53+
5454 var authenticateResult = await policyEvaluator . AuthenticateAsync ( policy , context ) ;
5555
5656 // Allow Anonymous skips all authorization
You can’t perform that action at this time.
0 commit comments