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 duplicate dictionary lookups #1651

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void AddProviderType<THandler, TOptions, TIdentityProvider>(string type)
/// <returns></returns>
public DynamicProviderType? FindProviderType(string type)
{
return _providers.ContainsKey(type) ? _providers[type] : null;
return _providers.GetValueOrDefault(type);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public Task WriteHttpResponse(ProtectedResourceErrorResult result, HttpContext c
var error = result.Error;
var errorDescription = result.ErrorDescription;

if (Constants.ProtectedResourceErrorStatusCodes.ContainsKey(error))
if (Constants.ProtectedResourceErrorStatusCodes.TryGetValue(error, out var code))
{
context.Response.StatusCode = Constants.ProtectedResourceErrorStatusCodes[error];
context.Response.StatusCode = code;
}

if (error == OidcConstants.ProtectedResourceErrors.ExpiredToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
var nonce = Context.Items["DPoP-Nonce"] as string;
Context.Response.Headers[HttpHeaders.DPoPNonce] = nonce;
}
else if (properties.Items.ContainsKey("DPoP-Nonce"))
else if (properties.Items.TryGetValue("DPoP-Nonce", out var nonce))
{
// this allows the API itself to set the nonce
var nonce = properties.Items["DPoP-Nonce"];
Context.Response.Headers[HttpHeaders.DPoPNonce] = nonce;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/IdentityServer/Test/TestUserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public TestUser AutoProvisionUser(string provider, string userId, List<Claim> cl
filtered.Add(new Claim(JwtClaimTypes.Name, claim.Value));
}
// if the JWT handler has an outbound mapping to an OIDC claim use that
else if (JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.ContainsKey(claim.Type))
else if (JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.TryGetValue(claim.Type, out var value))
{
filtered.Add(new Claim(JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap[claim.Type], claim.Value));
filtered.Add(new Claim(value, claim.Value));
}
// copy the claim as-is
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ public string this[string key]
{
get
{
if (Inputs.ContainsKey(key)) return Inputs[key];
return null;
return Inputs.GetValueOrDefault(key);
}
set
{
Expand Down
Loading