diff --git a/CredentialProvider.Microsoft/CredentialProviderArgs.cs b/CredentialProvider.Microsoft/CredentialProviderArgs.cs index 5a912bdb..05420095 100644 --- a/CredentialProvider.Microsoft/CredentialProviderArgs.cs +++ b/CredentialProvider.Microsoft/CredentialProviderArgs.cs @@ -8,9 +8,9 @@ namespace NuGetCredentialProvider { - [ArgDescription("The Azure Artifacts credential provider can be used to aquire credentials for Azure Artifacts.\n" + + [ArgDescription("The Azure Artifacts credential provider can be used to acquire credentials for Azure Artifacts.\n" + "\n" + - "Note: The Azure Artifacts Credential Provider is mainly intended for use via integrations with development tools such as .NET Core and nuget.exe.\n" + + "Note: The Azure Artifacts Credential Provider is mainly intended for use via integrations with development tools such as .NET Core and nuget.exe.\n" + "While it can be used via this CLI in \"stand-alone mode\", please pay special attention to certain options such as -IsRetry below.\n" + "Failing to do so may result in obtaining invalid credentials.")] internal class CredentialProviderArgs @@ -39,6 +39,7 @@ internal class CredentialProviderArgs [ArgDescription("Prints this help message")] public bool Help { get; set; } + [ArgDefaultValue(true)] [ArgDescription("If true, user can be prompted with credentials through UI, if false, device flow must be used")] public bool CanShowDialog { get; set; } diff --git a/CredentialProvider.Microsoft/CredentialProviders/Vsts/MSAL/MsalTokenProvider.cs b/CredentialProvider.Microsoft/CredentialProviders/Vsts/MSAL/MsalTokenProvider.cs index efadb254..01bfe033 100644 --- a/CredentialProvider.Microsoft/CredentialProviders/Vsts/MSAL/MsalTokenProvider.cs +++ b/CredentialProvider.Microsoft/CredentialProviders/Vsts/MSAL/MsalTokenProvider.cs @@ -178,13 +178,19 @@ public async Task AcquireTokenSilentlyAsync(CancellationToken cancel public async Task AcquireTokenWithUI(CancellationToken cancellationToken, ILogger logging) { + var publicClient = await GetPCAAsync(useLocalHost: true).ConfigureAwait(false); + + if (!publicClient.IsUserInteractive()) + { + this.Logger.Verbose("Not user interactive"); + return null; + } + var deviceFlowTimeout = EnvUtil.GetDeviceFlowTimeoutFromEnvironmentInSeconds(logging); using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); cts.CancelAfter(TimeSpan.FromSeconds(deviceFlowTimeout)); - var publicClient = await GetPCAAsync(useLocalHost: true).ConfigureAwait(false); - try { var result = await publicClient.AcquireTokenInteractive(new string[] { resource }) diff --git a/CredentialProvider.Microsoft/Program.cs b/CredentialProvider.Microsoft/Program.cs index d7b1731d..d63f3e06 100644 --- a/CredentialProvider.Microsoft/Program.cs +++ b/CredentialProvider.Microsoft/Program.cs @@ -7,7 +7,6 @@ using System.IO; using System.Net.Http.Headers; using System.Reflection; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json;