-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
#913 #1066 ScopesAuthorizer refactoring #1478
base: develop
Are you sure you want to change the base?
Changes from all commits
c85b7c1
5090cbc
63f8973
3c9fc3d
a05514c
d8510a5
659cb1e
708c321
f1f613f
ecb22c7
528db09
d9fd3bd
d9e8e74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Ocelot.Infrastructure.Claims.Parser; | ||
using Ocelot.Infrastructure.Claims.Parser; | ||
using Ocelot.Responses; | ||
using System.Security.Claims; | ||
|
||
|
@@ -28,14 +28,22 @@ public Response<bool> Authorize(ClaimsPrincipal claimsPrincipal, List<string> ro | |
return new ErrorResponse<bool>(values.Errors); | ||
} | ||
|
||
var userScopes = values.Data; | ||
IList<string> userScopes = values.Data; | ||
|
||
var matchesScopes = routeAllowedScopes.Intersect(userScopes); | ||
if (userScopes.Count == 1) | ||
{ | ||
var scope = userScopes[0]; | ||
|
||
if (scope.Contains(' ')) | ||
{ | ||
userScopes = scope.Split(' ', StringSplitOptions.RemoveEmptyEntries); | ||
} | ||
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's impossible to predict the body (serialized data) of the token from an unknown Auth-provider. |
||
} | ||
|
||
if (!matchesScopes.Any()) | ||
if (routeAllowedScopes.Except(userScopes).Any()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic inversion is feasible, yet it appears redundant. It seems to be a minor refactoring aimed at reducing the number of lines in the code. Additionally, the valuable suggestion from the previous code review was overlooked. This recommendation is more logical than the favored |
||
{ | ||
return new ErrorResponse<bool>( | ||
new ScopeNotAuthorizedError($"no one user scope: '{string.Join(',', userScopes)}' match with some allowed scope: '{string.Join(',', routeAllowedScopes)}'")); | ||
new ScopeNotAuthorizedError($"User scopes: '{string.Join(',', userScopes)}' do not have all allowed route scopes: '{string.Join(',', routeAllowedScopes)}'")); | ||
} | ||
|
||
return new OkResponse<bool>(true); | ||
|
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.
The
if
-block ought to be relocated toIClaimsParser
to preserve the existing logic intact. Consequently, you must inject your specializedIClaimsParser
service to generate the precise list of claims.