From 8be5b080afc89af03f6a2b96b3981f3077b8f9a0 Mon Sep 17 00:00:00 2001 From: "Ziheng Zhou (Wicresoft North America Ltd)" Date: Fri, 10 Jan 2020 17:53:40 +0800 Subject: [PATCH 1/2] update for environment --- sdk/identity/Azure.Identity/src/EnvironmentCredential.cs | 6 ++++++ sdk/identity/Azure.Identity/src/EnvironmentVariables.cs | 1 + 2 files changed, 7 insertions(+) diff --git a/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs b/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs index 2d20a1bb8df13..5ca7959b02560 100644 --- a/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs +++ b/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs @@ -59,6 +59,8 @@ internal EnvironmentCredential(CredentialPipeline pipeline) string username = EnvironmentVariables.Username; string password = EnvironmentVariables.Password; string sdkAuthLocation = EnvironmentVariables.SdkAuthLocation; + string clientCertificatePath = EnvironmentVariables.ClientCertificatePath; + var clientCertificate = new X509Certificate2(Encoding.ASCII.GetBytes(clientCertificatePath)); if (tenantId != null && clientId != null) { @@ -66,6 +68,10 @@ internal EnvironmentCredential(CredentialPipeline pipeline) { _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); diff --git a/sdk/identity/Azure.Identity/src/EnvironmentVariables.cs b/sdk/identity/Azure.Identity/src/EnvironmentVariables.cs index b9b853f500b8b..6ff571a2c1807 100644 --- a/sdk/identity/Azure.Identity/src/EnvironmentVariables.cs +++ b/sdk/identity/Azure.Identity/src/EnvironmentVariables.cs @@ -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"); } } From a82cdd0a9ba700de0275d51a788ccd6e14ef9e77 Mon Sep 17 00:00:00 2001 From: "Ziheng Zhou (Wicresoft North America Ltd)" Date: Wed, 15 Jan 2020 17:39:43 +0800 Subject: [PATCH 2/2] update for EnvironmentCredential --- sdk/identity/Azure.Identity/src/EnvironmentCredential.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs b/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs index 5ca7959b02560..728546ee0373a 100644 --- a/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs +++ b/sdk/identity/Azure.Identity/src/EnvironmentCredential.cs @@ -60,7 +60,7 @@ internal EnvironmentCredential(CredentialPipeline pipeline) string password = EnvironmentVariables.Password; string sdkAuthLocation = EnvironmentVariables.SdkAuthLocation; string clientCertificatePath = EnvironmentVariables.ClientCertificatePath; - var clientCertificate = new X509Certificate2(Encoding.ASCII.GetBytes(clientCertificatePath)); + var clientCertificate = new X509Certificate2(clientCertificatePath); if (tenantId != null && clientId != null) {