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

Update EnvironmentCredential and EnvironmentVariables #9430

Closed
Closed
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
6 changes: 6 additions & 0 deletions sdk/identity/Azure.Identity/src/EnvironmentCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ internal EnvironmentCredential(CredentialPipeline pipeline)
string username = EnvironmentVariables.Username;
string password = EnvironmentVariables.Password;
string sdkAuthLocation = EnvironmentVariables.SdkAuthLocation;
string clientCertificatePath = EnvironmentVariables.ClientCertificatePath;
var clientCertificate = new X509Certificate2(clientCertificatePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The X509Certificate2 should only be instantiated in the if block below.

               else if (clientCertificate != null)
                {
                    var clientCertificate = new X509Certificate2(clientCertificatePath);

                    _credential = new ClientCertificateCredential(tenantId, clientId, clientCertificate, _pipeline);
                }


if (tenantId != null && clientId != null)
{
if (clientSecret != null)
{
_credential = new ClientSecretCredential(tenantId, clientId, clientSecret, _pipeline);
}
else if (clientCertificate != null)
{
_credential = new ClientCertificateCredential(tenantId, clientId, clientCertificate, _pipeline);
}
else if (username != null && password != null && tenantId != null && clientId != null)
{
_credential = new UsernamePasswordCredential(username, password, clientId, tenantId, _pipeline);
Expand Down
1 change: 1 addition & 0 deletions sdk/identity/Azure.Identity/src/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ internal class EnvironmentVariables

public static string MsiEndpoint => Environment.GetEnvironmentVariable("MSI_ENDPOINT");
public static string MsiSecret => Environment.GetEnvironmentVariable("MSI_SECRET");
public static string ClientCertificatePath => Environment.GetEnvironmentVariable("AZURE_CLIENT_CERTIFICATE_PATH");
}
}