File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 2.5.1.0
1+ 2.5.1.1
Original file line number Diff line number Diff line change @@ -92,6 +92,11 @@ public class ServicePrincipalIdentity
9292 /// If both <see cref="Certificate"/> and <see cref="ClientSecret"/> are set, the certificate will be used.
9393 /// </remarks>
9494 public string ClientSecret { get ; set ; }
95+
96+ /// <summary>
97+ /// Whether the authentication should send X5C
98+ /// </summary>
99+ public bool SendX5C { get ; set ; }
95100 }
96101
97102 public interface IMicrosoftAuthenticationResult
@@ -269,7 +274,15 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenForServicePrincipalAsy
269274
270275 try
271276 {
272- AuthenticationResult result = await app . AcquireTokenForClient ( scopes ) . ExecuteAsync ( ) ;
277+ var tokenBuilder = app . AcquireTokenForClient ( scopes ) ;
278+
279+ if ( sp . SendX5C )
280+ {
281+ tokenBuilder = tokenBuilder . WithSendX5C ( true ) ;
282+ }
283+
284+ AuthenticationResult result = await tokenBuilder . ExecuteAsync ( ) ;
285+
273286 return new MsalResult ( result ) ;
274287 }
275288 catch ( Exception ex )
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ public static class EnvironmentVariables
4444 public const string ServicePrincipalId = "GCM_AZREPOS_SERVICE_PRINCIPAL" ;
4545 public const string ServicePrincipalSecret = "GCM_AZREPOS_SP_SECRET" ;
4646 public const string ServicePrincipalCertificateThumbprint = "GCM_AZREPOS_SP_CERT_THUMBPRINT" ;
47+ public const string ServicePrincipalCertificateSendX5C = "GCM_AZREPOS_SP_CERT_SEND_X5C" ;
4748 public const string ManagedIdentity = "GCM_AZREPOS_MANAGEDIDENTITY" ;
4849 }
4950
@@ -59,6 +60,7 @@ public static class Credential
5960 public const string ServicePrincipal = "azreposServicePrincipal" ;
6061 public const string ServicePrincipalSecret = "azreposServicePrincipalSecret" ;
6162 public const string ServicePrincipalCertificateThumbprint = "azreposServicePrincipalCertificateThumbprint" ;
63+ public const string ServicePrincipalCertificateSendX5C = "azreposServicePrincipalCertificateSendX5C" ;
6264 public const string ManagedIdentity = "azreposManagedIdentity" ;
6365 }
6466 }
Original file line number Diff line number Diff line change @@ -549,6 +549,14 @@ private bool UseServicePrincipal(out ServicePrincipalIdentity sp)
549549
550550 if ( hasCertThumbprint )
551551 {
552+ bool hasX5CSetting = _context . Settings . TryGetSetting (
553+ AzureDevOpsConstants . EnvironmentVariables . ServicePrincipalCertificateSendX5C ,
554+ Constants . GitConfiguration . Credential . SectionName ,
555+ AzureDevOpsConstants . GitConfiguration . Credential . ServicePrincipalCertificateSendX5C ,
556+ out string certHasX5C ) ;
557+
558+ sp . SendX5C = ! hasX5CSetting || certHasX5C == "false" ;
559+
552560 X509Certificate2 cert = X509Utils . GetCertificateByThumbprint ( certThumbprint ) ;
553561 if ( cert is null )
554562 {
You can’t perform that action at this time.
0 commit comments