File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Expand file tree Collapse file tree 4 files changed +25
-2
lines changed 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
92
92
/// If both <see cref="Certificate"/> and <see cref="ClientSecret"/> are set, the certificate will be used.
93
93
/// </remarks>
94
94
public string ClientSecret { get ; set ; }
95
+
96
+ /// <summary>
97
+ /// Whether the authentication should send X5C
98
+ /// </summary>
99
+ public bool SendX5C { get ; set ; }
95
100
}
96
101
97
102
public interface IMicrosoftAuthenticationResult
@@ -269,7 +274,15 @@ public async Task<IMicrosoftAuthenticationResult> GetTokenForServicePrincipalAsy
269
274
270
275
try
271
276
{
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
+
273
286
return new MsalResult ( result ) ;
274
287
}
275
288
catch ( Exception ex )
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ public static class EnvironmentVariables
44
44
public const string ServicePrincipalId = "GCM_AZREPOS_SERVICE_PRINCIPAL" ;
45
45
public const string ServicePrincipalSecret = "GCM_AZREPOS_SP_SECRET" ;
46
46
public const string ServicePrincipalCertificateThumbprint = "GCM_AZREPOS_SP_CERT_THUMBPRINT" ;
47
+ public const string ServicePrincipalCertificateSendX5C = "GCM_AZREPOS_SP_CERT_SEND_X5C" ;
47
48
public const string ManagedIdentity = "GCM_AZREPOS_MANAGEDIDENTITY" ;
48
49
}
49
50
@@ -59,6 +60,7 @@ public static class Credential
59
60
public const string ServicePrincipal = "azreposServicePrincipal" ;
60
61
public const string ServicePrincipalSecret = "azreposServicePrincipalSecret" ;
61
62
public const string ServicePrincipalCertificateThumbprint = "azreposServicePrincipalCertificateThumbprint" ;
63
+ public const string ServicePrincipalCertificateSendX5C = "azreposServicePrincipalCertificateSendX5C" ;
62
64
public const string ManagedIdentity = "azreposManagedIdentity" ;
63
65
}
64
66
}
Original file line number Diff line number Diff line change @@ -549,6 +549,14 @@ private bool UseServicePrincipal(out ServicePrincipalIdentity sp)
549
549
550
550
if ( hasCertThumbprint )
551
551
{
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
+
552
560
X509Certificate2 cert = X509Utils . GetCertificateByThumbprint ( certThumbprint ) ;
553
561
if ( cert is null )
554
562
{
You can’t perform that action at this time.
0 commit comments