Skip to content

Commit a5d19e1

Browse files
committed
entra: expose public client configuration
Consumer currently cannot determine which application registration or capabilities back an Entra authentication instance after it has been constructed. Azure Repos needs this information to distinguish its new client application from the legacy fallback. Expose the immutable public client configuration through the authentication interface and use it as the implementation's single source of configuration state. Assisted-by: GPT-5.6 Sol Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent d5b3cbf commit a5d19e1

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎src/Core/Authentication/Entra/EntraAuthentication.Caching.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal StorageCreationProperties CreateUserTokenCacheProps(bool useLinuxFallba
103103
// If we are using the shared Microsoft Developer cache there are a different set of
104104
// file paths, names, and keychain/keyring attributes to use.
105105
// The shared cache is used by other Microsoft developer tools such as Visual Studio.
106-
if (_publicClientConfig.UseSharedCache)
106+
if (PublicClientConfig.UseSharedCache)
107107
{
108108
Context.Trace.WriteLine("Using shared Microsoft Developer MSAL cache");
109109

‎src/Core/Authentication/Entra/EntraAuthentication.PublicClient.cs‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public record PublicClientConfig
6868
public partial class EntraAuthentication
6969
{
7070
private const string MacBrokerRedirectUrl = "msauth.com.msauth.unsignedapp://auth";
71-
private readonly PublicClientConfig _publicClientConfig;
71+
72+
public PublicClientConfig PublicClientConfig { get; }
7273

7374
public async Task<InteractionMode> GetInteractionModeAsync(CancellationToken ct = default)
7475
{
@@ -219,7 +220,7 @@ private async Task<AuthenticationResult> GetTokenForUserSilentAsync(
219220
try
220221
{
221222
return await app.AcquireTokenSilent(scopes, msalAccount)
222-
.WithMsaPassthroughTransfer(_publicClientConfig.IsMsaPassthroughEnabled, msalAccount)
223+
.WithMsaPassthroughTransfer(PublicClientConfig.IsMsaPassthroughEnabled, msalAccount)
223224
.ExecuteAsync(ct);
224225
}
225226
catch (MsalUiRequiredException)
@@ -439,7 +440,7 @@ private Task ShowDeviceCodeAsync(DeviceCodeResult dcr)
439440
/// <param name="useBroker">True if the broker will be used for this applications build using this builder.</param>
440441
private PublicClientApplicationBuilder GetPublicAppBuilder(out bool useBroker)
441442
{
442-
if (_publicClientConfig is null)
443+
if (PublicClientConfig is null)
443444
{
444445
throw new InvalidOperationException(
445446
"Public client configuration is required for user authentication.");
@@ -448,7 +449,7 @@ private PublicClientApplicationBuilder GetPublicAppBuilder(out bool useBroker)
448449
if (_publicBuilder is null)
449450
{
450451
Context.Trace.WriteLine("Creating public client application builder...");
451-
var builder = PublicClientApplicationBuilder.Create(_publicClientConfig.ClientId)
452+
var builder = PublicClientApplicationBuilder.Create(PublicClientConfig.ClientId)
452453
.WithHttpClientFactory(_httpFactory)
453454
.WithTraceLogging(Context)
454455
.WithLegacyCacheCompatibility(false)
@@ -459,9 +460,9 @@ private PublicClientApplicationBuilder GetPublicAppBuilder(out bool useBroker)
459460
if (Context.SessionManager.IsDesktopSession && IsBrokerEnabled())
460461
{
461462
// Check that the app config supports the broker on this platform
462-
if (_publicClientConfig.SupportsWindowsBroker && PlatformUtils.IsWindows() ||
463-
_publicClientConfig.SupportsMacBroker && PlatformUtils.IsMacOS() ||
464-
_publicClientConfig.SupportsLinuxBroker && PlatformUtils.IsLinux())
463+
if (PublicClientConfig.SupportsWindowsBroker && PlatformUtils.IsWindows() ||
464+
PublicClientConfig.SupportsMacBroker && PlatformUtils.IsMacOS() ||
465+
PublicClientConfig.SupportsLinuxBroker && PlatformUtils.IsLinux())
465466
{
466467
Context.Trace.WriteLine("Broker is supported by the app and enabled by the user.");
467468

@@ -514,20 +515,20 @@ private BrokerOptions GetBrokerOptions()
514515
{
515516
var oses = BrokerOptions.OperatingSystems.None;
516517

517-
if (_publicClientConfig.SupportsWindowsBroker)
518+
if (PublicClientConfig.SupportsWindowsBroker)
518519
oses |= BrokerOptions.OperatingSystems.Windows;
519520

520-
if (_publicClientConfig.SupportsMacBroker)
521+
if (PublicClientConfig.SupportsMacBroker)
521522
oses |= BrokerOptions.OperatingSystems.OSX;
522523

523-
if (_publicClientConfig.SupportsLinuxBroker)
524+
if (PublicClientConfig.SupportsLinuxBroker)
524525
oses |= BrokerOptions.OperatingSystems.Linux;
525526

526527
return new BrokerOptions(oses)
527528
{
528529
Title = "Git Credential Manager",
529530
ListOperatingSystemAccounts = true,
530-
MsaPassthrough = _publicClientConfig.IsMsaPassthroughEnabled
531+
MsaPassthrough = PublicClientConfig.IsMsaPassthroughEnabled
531532
};
532533
}
533534

‎src/Core/Authentication/Entra/EntraAuthentication.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class EntraAuthentication : AuthenticationBase, IEntraAuthenticat
2121
public EntraAuthentication(ICommandContext context, PublicClientConfig publicClientConfig = null)
2222
: base(context)
2323
{
24-
_publicClientConfig = publicClientConfig;
24+
PublicClientConfig = publicClientConfig;
2525
_httpFactory = new MsalHttpClientFactoryAdaptor(context.HttpClientFactory);
2626
}
2727

‎src/Core/Authentication/Entra/IEntraAuthentication.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ namespace GitCredentialManager.Authentication.Entra;
66

77
public interface IEntraAuthentication
88
{
9+
/// <summary>
10+
/// The public client configuration used for authentication.
11+
/// </summary>
12+
/// <remarks>If this property is null then public client APIs cannot be called.</remarks>
13+
PublicClientConfig PublicClientConfig { get; }
14+
915
/// <summary>
1016
/// Ask the user which interaction mode they would like to use for authentication.
1117
/// </summary>

0 commit comments

Comments
 (0)