Skip to content

Commit d5b3cbf

Browse files
committed
azrepos: use the GCM Entra application
Azure Repos OAuth currently identifies GCM as the Visual Studio application. That client registration does not provide the redirect URIs required for broker authentication on macOS and Linux. Use GCM's dedicated first-party Entra application by default and enable broker support on all supported platforms. Retain the Visual Studio client ID as an explicit compatibility fallback while replacing the unrestricted developer overrides with a narrow, documented setting. Assisted-by: GPT-5.6 Sol Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent c3a0061 commit d5b3cbf

5 files changed

Lines changed: 74 additions & 35 deletions

File tree

‎docs/configuration.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,27 @@ git config --global credential.azreposUseMicrosoftSharedCache false
848848

849849
---
850850

851+
### credential.azreposUseLegacyClientId
852+
853+
Use the legacy Visual Studio Entra application when authenticating to Azure
854+
Repos with Microsoft identity OAuth tokens. Set this value to `true` to restore
855+
the application identity used by earlier versions of GCM.
856+
857+
The legacy application does not support broker authentication on macOS or
858+
Linux.
859+
860+
Defaults to `false`.
861+
862+
#### Example
863+
864+
```shell
865+
git config --global credential.azreposUseLegacyClientId true
866+
```
867+
868+
**Also see: [GCM_AZREPOS_USE_LEGACY_CLIENTID][gcm-azrepos-legacy-client-id]**
869+
870+
---
871+
851872
### credential.azreposCredentialType
852873

853874
Specify the type of credential the Azure Repos host provider should return.
@@ -1201,6 +1222,7 @@ Defaults to disabled.
12011222
[gcm-autodetect-timeout]: environment.md#GCM_AUTODETECT_TIMEOUT
12021223
[gcm-azrepos-credentialtype]: environment.md#GCM_AZREPOS_CREDENTIALTYPE
12031224
[gcm-azrepos-shared-cache]: environment.md#GCM_AZREPOS_USE_MSFT_CACHE
1225+
[gcm-azrepos-legacy-client-id]: environment.md#GCM_AZREPOS_USE_LEGACY_CLIENTID
12041226
[gcm-azrepos-credentialmanagedidentity]: environment.md#GCM_AZREPOS_MANAGEDIDENTITY
12051227
[gcm-azrepos-wif]: environment.md#GCM_AZREPOS_WIF
12061228
[gcm-azrepos-wif-clientid]: environment.md#GCM_AZREPOS_WIF_CLIENTID

‎docs/environment.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,33 @@ export GCM_AZREPOS_USE_MSFT_CACHE="false"
947947

948948
---
949949

950+
### GCM_AZREPOS_USE_LEGACY_CLIENTID
951+
952+
Use the legacy Visual Studio Entra application when authenticating to Azure
953+
Repos with Microsoft identity OAuth tokens. Set this value to `true` to restore
954+
the application identity used by earlier versions of GCM.
955+
956+
The legacy application does not support broker authentication on macOS or
957+
Linux.
958+
959+
Defaults to `false`.
960+
961+
#### Windows
962+
963+
```batch
964+
SET GCM_AZREPOS_USE_LEGACY_CLIENTID=true
965+
```
966+
967+
#### macOS/Linux
968+
969+
```bash
970+
export GCM_AZREPOS_USE_LEGACY_CLIENTID="true"
971+
```
972+
973+
**Also see: [credential.azreposUseLegacyClientId][legacy-client-id]**
974+
975+
---
976+
950977
### GCM_AZREPOS_CREDENTIALTYPE
951978

952979
Specify the type of credential the Azure Repos host provider should return.
@@ -1379,6 +1406,7 @@ Defaults to disabled.
13791406
[credential-autodetecttimeout]: configuration.md#credentialautodetecttimeout
13801407
[credential-azrepos-credential-type]: configuration.md#credentialazreposcredentialtype
13811408
[shared-cache]: configuration.md#credentialazreposusemicrosoftsharedcache
1409+
[legacy-client-id]: configuration.md#credentialazreposuselegacyclientid
13821410
[credential-azrepos-managedidentity]: configuration.md#credentialazreposmanagedidentity
13831411
[credential-azrepos-wif]: configuration.md#credentialazreposworkloadfederation
13841412
[credential-azrepos-wif-clientid]: configuration.md#credentialazreposworkloadfederationclientid

‎src/Microsoft.AzureRepos/AzureDevOpsConstants.cs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
31
namespace Microsoft.AzureRepos
42
{
53
internal static class AzureDevOpsConstants
@@ -11,9 +9,11 @@ internal static class AzureDevOpsConstants
119
public const string AzureDevOpsResourceId = "499b84ac-1321-427f-aa17-267ca6975798";
1210
public static readonly string[] AzureDevOpsDefaultScopes = {$"{AzureDevOpsResourceId}/.default"};
1311

12+
// The GCM first party application client ID
13+
public const string ClientId = "d735b71b-9eee-4a4f-ad23-421660877ba6";
14+
1415
// Visual Studio's client ID
15-
// We share this to be able to consume existing access tokens from the VS caches
16-
public const string AadClientId = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
16+
public const string LegacyClientId = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
1717

1818
public const string VstsHostSuffix = ".visualstudio.com";
1919
public const string AzureDevOpsHost = "dev.azure.com";
@@ -34,9 +34,8 @@ public static class PersonalAccessTokenScopes
3434

3535
public static class EnvironmentVariables
3636
{
37-
public const string DevAadClientId = "GCM_DEV_AZREPOS_CLIENTID";
38-
public const string DevAadAuthorityBaseUri = "GCM_DEV_AZREPOS_AUTHORITYBASEURI";
3937
public const string UseSharedCache = "GCM_AZREPOS_USE_MSFT_CACHE";
38+
public const string UseLegacyClientId = "GCM_AZREPOS_USE_LEGACY_CLIENTID";
4039
public const string CredentialType = "GCM_AZREPOS_CREDENTIALTYPE";
4140
public const string ServicePrincipalId = "GCM_AZREPOS_SERVICE_PRINCIPAL";
4241
public const string ServicePrincipalSecret = "GCM_AZREPOS_SP_SECRET";
@@ -55,9 +54,8 @@ public static class GitConfiguration
5554
{
5655
public static class Credential
5756
{
58-
public const string DevAadClientId = "azreposDevClientId";
59-
public const string DevAadAuthorityBaseUri = "azreposDevAuthorityBaseUri";
6057
public const string UseSharedCache = "azreposUseMicrosoftSharedCache";
58+
public const string UseLegacyClientId = "azreposUseLegacyClientId";
6159
public const string CredentialType = "azreposCredentialType";
6260
public const string AzureAuthority = "azureAuthority";
6361
public const string ServicePrincipal = "azreposServicePrincipal";

‎src/Microsoft.AzureRepos/AzureDevOpsRestApi.cs‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task<string> GetAuthorityAsync(Uri organizationUri)
3131
{
3232
EnsureArgument.AbsoluteUri(organizationUri, nameof(organizationUri));
3333

34-
Uri authorityBase = GetAuthorityBaseUri();
34+
Uri authorityBase = new(AzureDevOpsConstants.AadAuthorityBaseUrl);
3535
var commonAuthority = new Uri(authorityBase, "common");
3636

3737
// We should be using "/common" or "/consumer" as the authority for MSA but since
@@ -88,21 +88,6 @@ public async Task<string> GetAuthorityAsync(Uri organizationUri)
8888
return commonAuthority.ToString();
8989
}
9090

91-
private Uri GetAuthorityBaseUri()
92-
{
93-
// Check for developer override value
94-
if (_context.Settings.TryGetSetting(
95-
AzureDevOpsConstants.EnvironmentVariables.DevAadAuthorityBaseUri,
96-
Constants.GitConfiguration.Credential.SectionName, AzureDevOpsConstants.GitConfiguration.Credential.DevAadAuthorityBaseUri,
97-
out string redirectUriStr) &&
98-
Uri.TryCreate(redirectUriStr, UriKind.Absolute, out Uri authorityBase))
99-
{
100-
return authorityBase;
101-
}
102-
103-
return new Uri(AzureDevOpsConstants.AadAuthorityBaseUrl);
104-
}
105-
10691
public async Task<string> CreatePersonalAccessTokenAsync(Uri organizationUri, string accessToken, IEnumerable<string> scopes)
10792
{
10893
const string sessionTokenUrl = "_apis/token/sessiontokens?api-version=1.0&tokentype=compact";

‎src/Microsoft.AzureRepos/AzureReposHostProvider.cs‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,21 @@ private async Task<IEntraAuthenticationResult> GetEntraAccessTokenAsync(GitReque
402402

403403
private PublicClientConfig GetEntraConfig()
404404
{
405+
(string clientId, bool isLegacy) = GetClientAppInfo();
406+
407+
_context.Trace.WriteLine(isLegacy
408+
? $"Using legacy Entra client ID '{clientId}'"
409+
: $"Using new Entra client ID '{clientId}'");
410+
405411
return new PublicClientConfig
406412
{
407-
ClientId = GetClientId(),
413+
ClientId = clientId,
408414
IsMsaPassthroughEnabled = true,
409415
UseSharedCache = GetUseSharedCache(),
410416
SupportsWindowsBroker = true,
411-
// TODO: enable once our app registration has the appropriate redirect URLs
412-
//SupportsMacBroker = true,
413-
//SupportsLinuxBroker = true,
417+
// Only the new client ID supports broker on Mac and Linux
418+
SupportsMacBroker = !isLegacy,
419+
SupportsLinuxBroker = !isLegacy,
414420
};
415421
}
416422

@@ -430,19 +436,19 @@ internal bool GetUseSharedCache()
430436
return defaultValue;
431437
}
432438

433-
private string GetClientId()
439+
private (string clientId, bool isLegacy) GetClientAppInfo()
434440
{
435-
// Check for developer override value
441+
// Check for override to use the legacy client ID
436442
if (_context.Settings.TryGetSetting(
437-
AzureDevOpsConstants.EnvironmentVariables.DevAadClientId,
443+
AzureDevOpsConstants.EnvironmentVariables.UseLegacyClientId,
438444
Constants.GitConfiguration.Credential.SectionName,
439-
AzureDevOpsConstants.GitConfiguration.Credential.DevAadClientId,
440-
out string clientId))
445+
AzureDevOpsConstants.GitConfiguration.Credential.UseLegacyClientId,
446+
out string str) && str.IsTruthy())
441447
{
442-
return clientId;
448+
return (AzureDevOpsConstants.LegacyClientId, true);
443449
}
444450

445-
return AzureDevOpsConstants.AadClientId;
451+
return (AzureDevOpsConstants.ClientId, false);
446452
}
447453

448454
/// <remarks>

0 commit comments

Comments
 (0)