Skip to content

Commit

Permalink
Merge pull request #1651 from SimonCropp:remove-duplicate-dictionary-…
Browse files Browse the repository at this point in the history
…lookups

remove duplicate dictionary lookups
  • Loading branch information
damianh authored Dec 3, 2024
2 parents df77918 + 178e2a1 commit c52f810
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
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

0 comments on commit c52f810

Please sign in to comment.