public async Task <NuGet.Configuration.ICredentialService> GetCredentialServiceAsync()
        {
            // Initialize the credential providers.
            var credentialProviders = new List <ICredentialProvider>();
            var webProxy            = await _asyncServiceProvider.GetServiceAsync <SVsWebProxy, IVsWebProxy>();

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioAccountProvider,
                () =>
            {
                var importer = new VsCredentialProviderImporter(
                    (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage));

                return(importer.GetProviders());
            });

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioCredentialProvider,
                () =>
            {
                Debug.Assert(webProxy != null);

                return(new ICredentialProvider[] {
                    new VisualStudioCredentialProvider(webProxy)
                });
            });

            await TryAddCredentialProvidersAsync(
                credentialProviders,
                Strings.CredentialProviderFailed_PluginCredentialProvider,
                async() => await(new SecurePluginCredentialProviderBuilder(PluginManager.Instance, canShowDialog: true, logger: NullLogger.Instance).BuildAllAsync())
                );

            if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders)
            {
                TryAddCredentialProviders(
                    credentialProviders,
                    Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider,
                    () =>
                {
                    return(new ICredentialProvider[] {
                        new DefaultNetworkCredentialsCredentialProvider()
                    });
                });
            }

            // can only interact when VS is not in server mode.
            bool nonInteractive = await VisualStudioContextHelper.IsInServerModeAsync(CancellationToken.None);

            // Initialize the credential service.
            var credentialService = new CredentialService(
                new AsyncLazy <IEnumerable <ICredentialProvider> >(() => System.Threading.Tasks.Task.FromResult((IEnumerable <ICredentialProvider>)credentialProviders)),
                nonInteractive: nonInteractive,
                handlesDefaultCredentials: PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders);

            return(credentialService);
        }
Exemple #2
0
        public async Task <NuGet.Configuration.ICredentialService> GetCredentialServiceAsync()
        {
            // Initialize the credential providers.
            var credentialProviders = new List <ICredentialProvider>();
            var dte = await _asyncServiceProvider.GetDTEAsync();

            var webProxy = await _asyncServiceProvider.GetServiceAsync <SVsWebProxy, IVsWebProxy>();

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioAccountProvider,
                () =>
            {
                var importer = new VsCredentialProviderImporter(
                    dte,
                    VisualStudioAccountProvider.FactoryMethod,
                    (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage));

                return(importer.GetProviders());
            });

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioCredentialProvider,
                () =>
            {
                Debug.Assert(webProxy != null);

                return(new ICredentialProvider[] {
                    new VisualStudioCredentialProvider(webProxy)
                });
            });

            await TryAddCredentialProvidersAsync(
                credentialProviders,
                Strings.CredentialProviderFailed_PluginCredentialProvider,
                async() => await(new SecureCredentialProviderBuilder(PluginManager.Instance, NullLogger.Instance).BuildAll())
                );

            if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders)
            {
                TryAddCredentialProviders(
                    credentialProviders,
                    Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider,
                    () =>
                {
                    return(new ICredentialProvider[] {
                        new DefaultCredentialsCredentialProvider()
                    });
                });
            }

            // Initialize the credential service.
            var credentialService = new CredentialService(new AsyncLazy <IEnumerable <ICredentialProvider> >(() => System.Threading.Tasks.Task.FromResult((IEnumerable <ICredentialProvider>)credentialProviders)), nonInteractive: false, handlesDefaultCredentials: PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders);

            return(credentialService);
        }
Exemple #3
0
        public NuGet.Configuration.ICredentialService GetCredentialService()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            // Initialize the credential providers.
            var credentialProviders = new List <ICredentialProvider>();

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioAccountProvider,
                () =>
            {
                var importer = new VsCredentialProviderImporter(
                    _serviceProvider.GetDTE(),
                    VisualStudioAccountProvider.FactoryMethod,
                    (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage));

                return(importer.GetProviders());
            });

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioCredentialProvider,
                () =>
            {
                var webProxy = (IVsWebProxy)_serviceProvider.GetService(typeof(SVsWebProxy));

                Debug.Assert(webProxy != null);

                return(new NuGet.Credentials.ICredentialProvider[] {
                    new VisualStudioCredentialProvider(webProxy)
                });
            });

            if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders)
            {
                TryAddCredentialProviders(
                    credentialProviders,
                    Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider,
                    () =>
                {
                    return(new NuGet.Credentials.ICredentialProvider[] {
                        new DefaultCredentialsCredentialProvider()
                    });
                });
            }

            // Initialize the credential service.
            var credentialService = new CredentialService(credentialProviders, nonInteractive: false);

            return(credentialService);
        }
Exemple #4
0
        public async Task <NuGet.Configuration.ICredentialService> GetCredentialServiceAsync()
        {
            // Initialize the credential providers.
            var credentialProviders = new List <ICredentialProvider>();
            var dte = await _asyncServiceProvider.GetDTEAsync();

            var webProxy = (IVsWebProxy)await _asyncServiceProvider.GetServiceAsync(typeof(SVsWebProxy));

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioAccountProvider,
                () =>
            {
                var importer = new VsCredentialProviderImporter(
                    dte,
                    VisualStudioAccountProvider.FactoryMethod,
                    (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage));

                return(importer.GetProviders());
            });

            TryAddCredentialProviders(
                credentialProviders,
                Strings.CredentialProviderFailed_VisualStudioCredentialProvider,
                () =>
            {
                Debug.Assert(webProxy != null);

                return(new ICredentialProvider[] {
                    new VisualStudioCredentialProvider(webProxy)
                });
            });

            if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders)
            {
                TryAddCredentialProviders(
                    credentialProviders,
                    Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider,
                    () =>
                {
                    return(new ICredentialProvider[] {
                        new DefaultCredentialsCredentialProvider()
                    });
                });
            }

            // Initialize the credential service.
            var credentialService = new CredentialService(credentialProviders, nonInteractive: false);

            return(credentialService);
        }