diff options
author | Jérémie Laval <jeremie.laval@gmail.com> | 2020-01-03 17:47:39 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@microsoft.com> | 2020-01-08 16:00:10 +0300 |
commit | 14686dcd0834b8962b6ffd2bd9a1548d482b3883 (patch) | |
tree | a255e0b7cbbe53eaa7bbdbd26b4c7468a154b954 /main/src/addins/MonoDevelop.PackageManagement | |
parent | d60a8d185a881f99e8b3315878b32c6bc210e3b2 (diff) |
[PackageManagement] Register credential providers coming from secure plugins
This will do a barebone registration of available, plugin-based credential providers (like the Azure DevOps one) without implementing any authentication flow. The idea is that users can pre-authenticate via another mean (manual MSBuild invocation or NuGet binary) and the IDE will, at least, be able to retrieve those cached credentials.
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
2 files changed, 19 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs index 44a38d885b..57c9b30abe 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementCredentialService.cs @@ -32,6 +32,7 @@ using MonoDevelop.Core; using NuGet.CommandLine; using NuGet.Credentials; using NuGet.Protocol; +using NuGet.Protocol.Plugins; namespace MonoDevelop.PackageManagement { @@ -60,6 +61,7 @@ namespace MonoDevelop.PackageManagement var credentialProviders = new List<ICredentialProvider>(); credentialProviders.Add (CreateSettingsCredentialProvider ()); + credentialProviders.AddRange (GetPluginsCredentialProviders ()); credentialProviders.Add (new MonoDevelopCredentialProvider ()); return credentialProviders; @@ -72,6 +74,17 @@ namespace MonoDevelop.PackageManagement return new SettingsCredentialProvider (packageSourceProvider); } + static IEnumerable<ICredentialProvider> GetPluginsCredentialProviders () + { + var builder = new SecurePluginCredentialProviderBuilder ( + PluginManager.Instance, + canShowDialog: false, + logger: NuGet.Common.NullLogger.Instance + ); + var providers = builder.BuildAllAsync ().Result; + return providers; + } + /// <summary> /// The credential service puts itself in a retry mode if a credential provider /// is checked. This results in credentials stored in the key chain being ignored diff --git a/main/src/addins/MonoDevelop.PackageManagement/NuGet.Credentials/CredentialService.cs b/main/src/addins/MonoDevelop.PackageManagement/NuGet.Credentials/CredentialService.cs index f189f62439..f4c412ff14 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/NuGet.Credentials/CredentialService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/NuGet.Credentials/CredentialService.cs @@ -103,13 +103,18 @@ namespace NuGet.Credentials CredentialResponse response; if (!TryFromCredentialCache (uri, type, isRetry, provider, out response)) { + /* Temporarily disable interactive-ness with secure plugin provider + * to avoid them blocking on requesting user-input for device flow auth + */ + var nonInteractive = _nonInteractive || provider is SecurePluginCredentialProvider; + response = await provider.GetAsync ( uri, proxy, type, message, isRetry, - _nonInteractive, + nonInteractive, cancellationToken); // Check that the provider gave us a valid response. |