Skip to content
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

remove redundant Any checks before enumeration #1634

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
7 changes: 2 additions & 5 deletions src/IdentityServer/IdentityServerUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@ public ClaimsPrincipal CreatePrincipal()
claims.Add(new Claim(JwtClaimTypes.AuthenticationTime, new DateTimeOffset(AuthenticationTime.Value).ToUnixTimeSeconds().ToString()));
}

if (AuthenticationMethods.Any())
foreach (var amr in AuthenticationMethods)
{
foreach (var amr in AuthenticationMethods)
{
claims.Add(new Claim(JwtClaimTypes.AuthenticationMethod, amr));
}
claims.Add(new Claim(JwtClaimTypes.AuthenticationMethod, amr));
}

claims.AddRange(AdditionalClaims);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ public async Task<IEnumerable<SecurityKeyInfo>> GetValidationKeysAsync()
foreach (var store in _validationKeysStores)
{
var validationKeys = await store.GetValidationKeysAsync();
if (validationKeys.Any())
{
keys.AddRange(validationKeys);
}
keys.AddRange(validationKeys);
}

return keys;
Expand Down
16 changes: 6 additions & 10 deletions src/IdentityServer/Validation/Default/TokenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,15 @@ private async Task<TokenValidationResult> ValidateJwtAsync(string jwtString,

// check the scope format (array vs space delimited string)
var scopes = claims.Where(c => c.Type == JwtClaimTypes.Scope).ToArray();
if (scopes.Any())
foreach (var scope in scopes)
{
foreach (var scope in scopes)
if (scope.Value.Contains(" "))
{
if (scope.Value.Contains(' '))
claims.Remove(scope);
var values = scope.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries);
foreach (var value in values)
{
claims.Remove(scope);

var values = scope.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries);
foreach (var value in values)
{
claims.Add(new Claim(JwtClaimTypes.Scope, value));
}
claims.Add(new Claim(JwtClaimTypes.Scope, value));
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/Storage/IdentityServerUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ public ClaimsPrincipal CreatePrincipal()
claims.Add(new Claim(JwtClaimTypes.AuthenticationTime, new DateTimeOffset(AuthenticationTime.Value).ToUnixTimeSeconds().ToString()));
}

if (AuthenticationMethods.Any())
foreach (var amr in AuthenticationMethods)
{
foreach (var amr in AuthenticationMethods)
{
claims.Add(new Claim(JwtClaimTypes.AuthenticationMethod, amr));
}
claims.Add(new Claim(JwtClaimTypes.AuthenticationMethod, amr));
}

claims.AddRange(AdditionalClaims);
Expand Down
Loading