Skip to content

Commit 5c86721

Browse files
author
Tiago Brenck
committed
Renamings and PR comments
1 parent 5132107 commit 5c86721

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

4-WebApp-your-API/4-2-B2C/TodoListService/AuthorizationPolicies/ScopesRequirement.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88

99
namespace TodoListService.AuthorizationPolicies
1010
{
11+
/// <summary>
12+
/// Requirement used in authorization policies, to check if the scope claim has at least one of the requirement values.
13+
/// Since the class also extends AuthorizationHandler, its dependency injection is done out of the box.
14+
/// </summary>
1115
public class ScopesRequirement : AuthorizationHandler<ScopesRequirement>, IAuthorizationRequirement
1216
{
13-
string[] _scopes;
17+
string[] _acceptedScopes;
1418

15-
public ScopesRequirement(params string[] scopes)
19+
public ScopesRequirement(params string[] acceptedScopes)
1620
{
17-
_scopes = scopes;
21+
_acceptedScopes = acceptedScopes;
1822
}
1923

2024
/// <summary>
21-
/// AuthorizationHandler that will check if the scope claim has the requirement value
25+
/// AuthorizationHandler that will check if the scope claim has at least one of the requirement values
2226
/// </summary>
2327
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
2428
ScopesRequirement requirement)
@@ -35,7 +39,7 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte
3539
if (scopeClaim == null)
3640
scopeClaim = context?.User?.FindFirst(ClaimConstants.Scope);
3741

38-
if (scopeClaim != null && scopeClaim.Value.Split(' ').Intersect(requirement._scopes).Any())
42+
if (scopeClaim != null && scopeClaim.Value.Split(' ').Intersect(requirement._acceptedScopes).Any())
3943
{
4044
context.Succeed(requirement);
4145
}

4-WebApp-your-API/4-2-B2C/TodoListService/Startup.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public void ConfigureServices(IServiceCollection services)
4848
options.AddPolicy("ReadScope",
4949
policy => policy.Requirements.Add(new ScopesRequirement("read")));
5050
});
51-
52-
// Registering an authorization handler that will check if the scope claim has the requirement specified by the policy
53-
//services.AddSingleton<IAuthorizationHandler, ScopesRequirement>();
5451
}
5552

5653
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

0 commit comments

Comments
 (0)