diff --git a/src/shared/Core/Authentication/MicrosoftAuthentication.cs b/src/shared/Core/Authentication/MicrosoftAuthentication.cs index c64ce4b9c..12bccf5fe 100644 --- a/src/shared/Core/Authentication/MicrosoftAuthentication.cs +++ b/src/shared/Core/Authentication/MicrosoftAuthentication.cs @@ -274,20 +274,14 @@ public async Task GetTokenForServicePrincipalAsy try { - var tokenBuilder = app.AcquireTokenForClient(scopes); - - if (sp.SendX5C) - { - tokenBuilder = tokenBuilder.WithSendX5C(true); - } - - AuthenticationResult result = await tokenBuilder.ExecuteAsync(); + Context.Trace.WriteLine($"Sending with X5C: '{sp.SendX5C}'."); + AuthenticationResult result = await app.AcquireTokenForClient(scopes).WithSendX5C(sp.SendX5C).ExecuteAsync();; return new MsalResult(result); } catch (Exception ex) { - Context.Trace.WriteLine($"Failed to acquire token for service principal '{sp.TenantId}/{sp.TenantId}'."); + Context.Trace.WriteLine($"Failed to acquire token for service principal '{sp.TenantId}/{sp.Id}'."); Context.Trace.WriteException(ex); throw; } diff --git a/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs b/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs index cdbf16133..9bd6c72a1 100644 --- a/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs +++ b/src/shared/Microsoft.AzureRepos/AzureReposHostProvider.cs @@ -555,7 +555,7 @@ private bool UseServicePrincipal(out ServicePrincipalIdentity sp) AzureDevOpsConstants.GitConfiguration.Credential.ServicePrincipalCertificateSendX5C, out string certHasX5C); - sp.SendX5C = !hasX5CSetting || certHasX5C == "false"; + sp.SendX5C = !hasX5CSetting || certHasX5C != "false"; X509Certificate2 cert = X509Utils.GetCertificateByThumbprint(certThumbprint); if (cert is null)