forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed idserver4 (ThreeMammals#547)
- Loading branch information
1 parent
edbe334
commit 0786614
Showing
13 changed files
with
150 additions
and
1,187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
using IdentityModel; | ||
using Ocelot.Responses; | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
using System.Linq; | ||
|
||
namespace Ocelot.Authorisation | ||
{ | ||
using Infrastructure.Claims.Parser; | ||
|
||
public class ScopesAuthoriser : IScopesAuthoriser | ||
{ | ||
private readonly IClaimsParser _claimsParser; | ||
|
||
public ScopesAuthoriser(IClaimsParser claimsParser) | ||
{ | ||
_claimsParser = claimsParser; | ||
} | ||
|
||
public Response<bool> Authorise(ClaimsPrincipal claimsPrincipal, List<string> routeAllowedScopes) | ||
{ | ||
if (routeAllowedScopes == null || routeAllowedScopes.Count == 0) | ||
{ | ||
return new OkResponse<bool>(true); | ||
} | ||
|
||
var values = _claimsParser.GetValuesByClaimType(claimsPrincipal.Claims, JwtClaimTypes.Scope); | ||
|
||
if (values.IsError) | ||
{ | ||
return new ErrorResponse<bool>(values.Errors); | ||
} | ||
|
||
var userScopes = values.Data; | ||
|
||
var matchesScopes = routeAllowedScopes.Intersect(userScopes).ToList(); | ||
|
||
if (matchesScopes.Count == 0) | ||
{ | ||
return new ErrorResponse<bool>( | ||
new ScopeNotAuthorisedError($"no one user scope: '{string.Join(",", userScopes)}' match with some allowed scope: '{string.Join(",", routeAllowedScopes)}'")); | ||
} | ||
|
||
return new OkResponse<bool>(true); | ||
} | ||
} | ||
} | ||
using Ocelot.Responses; | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
using System.Linq; | ||
|
||
namespace Ocelot.Authorisation | ||
{ | ||
using Infrastructure.Claims.Parser; | ||
|
||
public class ScopesAuthoriser : IScopesAuthoriser | ||
{ | ||
private readonly IClaimsParser _claimsParser; | ||
private readonly string _scope = "scope"; | ||
|
||
public ScopesAuthoriser(IClaimsParser claimsParser) | ||
{ | ||
_claimsParser = claimsParser; | ||
} | ||
|
||
public Response<bool> Authorise(ClaimsPrincipal claimsPrincipal, List<string> routeAllowedScopes) | ||
{ | ||
if (routeAllowedScopes == null || routeAllowedScopes.Count == 0) | ||
{ | ||
return new OkResponse<bool>(true); | ||
} | ||
|
||
var values = _claimsParser.GetValuesByClaimType(claimsPrincipal.Claims, _scope); | ||
|
||
if (values.IsError) | ||
{ | ||
return new ErrorResponse<bool>(values.Errors); | ||
} | ||
|
||
var userScopes = values.Data; | ||
|
||
var matchesScopes = routeAllowedScopes.Intersect(userScopes).ToList(); | ||
|
||
if (matchesScopes.Count == 0) | ||
{ | ||
return new ErrorResponse<bool>( | ||
new ScopeNotAuthorisedError($"no one user scope: '{string.Join(",", userScopes)}' match with some allowed scope: '{string.Join(",", routeAllowedScopes)}'")); | ||
} | ||
|
||
return new OkResponse<bool>(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.