Skip to content

Commit

Permalink
Ensure thread safety for CertificateServiceClientCredentialsFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-robinet-sw committed May 24, 2024
1 parent 9834b81 commit 42a3b92
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,17 @@ public override Task<ServiceClientCredentials> CreateCredentialsAsync(
}

// Instance must be reused per audience, otherwise it will cause throttling on AAD.
_certificateAppCredentialsByAudience.TryGetValue(audience, out var certificateAppCredentials);
if (certificateAppCredentials == null)
var certificateAppCredentials = _certificateAppCredentialsByAudience.GetOrAdd(audience, (audience) =>
{
certificateAppCredentials = new CertificateAppCredentials(
return new CertificateAppCredentials(
_certificate,
_appId,
_tenantId,
audience,
_sendX5c,
_httpClient,
_logger);
_certificateAppCredentialsByAudience.TryAdd(audience, certificateAppCredentials);
}
});

return Task.FromResult<ServiceClientCredentials>(certificateAppCredentials);
}
Expand Down

0 comments on commit 42a3b92

Please sign in to comment.