Skip to content

Commit

Permalink
Default CanShowDialog to true for stand-alone mode (#376)
Browse files Browse the repository at this point in the history
* Default CanShowDialog to true for stand-alone mode

* Check if interactive auth is supported
  • Loading branch information
JohnSchmeichel committed Apr 19, 2023
1 parent 0ddbe1b commit c4c3a31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CredentialProvider.Microsoft/CredentialProviderArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,19 @@ public async Task<IMsalToken> AcquireTokenSilentlyAsync(CancellationToken cancel

public async Task<IMsalToken> 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 })
Expand Down
1 change: 0 additions & 1 deletion CredentialProvider.Microsoft/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c4c3a31

Please sign in to comment.