public async Task<AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed)
        {
            Log.Debug("Requesting credentials for '{0}'", uri);

            bool? result = null;

            var credentials = new AuthenticationCredentials(uri);

            using (_pleaseWaitInterruptService.Value.InterruptTemporarily())
            {
                await DispatchHelper.DispatchIfNecessaryAsync(() =>
                {
                    var uriString = uri.ToString().ToLower();

                    using (var scopeManager = ScopeManager<AuthenticationScope>.GetScopeManager(uriString.GetSafeScopeName(), () => new AuthenticationScope()))
                    {
                        var authenticationScope = scopeManager.ScopeObject;

                        var credentialsPrompter = new CredentialsPrompter(_configurationService)
                        {
                            Target = uriString,
                            UserName = string.Empty,
                            Password = string.Empty,
                            AllowStoredCredentials = !previousCredentialsFailed,
                            ShowSaveCheckBox = true,
                            WindowTitle = "Credentials required",
                            MainInstruction = "Credentials are required to access this feed",
                            Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri),
                            IsAuthenticationRequired = authenticationScope.CanPromptForAuthentication
                        };

                        authenticationScope.HasPromptedForAuthentication = true;

                        result = credentialsPrompter.ShowDialog();
                        if (result ?? false)
                        {
                            credentials.UserName = credentialsPrompter.UserName;
                            credentials.Password = credentialsPrompter.Password;
                        }
                        else
                        {
                            credentials.StoreCredentials = false;
                        }
                    }
                });
            }

            if (result ?? false)
            {
                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName);

                return credentials;
            }

            Log.Debug("Failed to request credentials for '{0}'", uri);

            return null;
        }
Example #2
0
        public async Task <AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed)
        {
            Log.Debug("Requesting credentials for '{0}'", uri);

            bool?result = null;

            var credentials = new AuthenticationCredentials(uri);

            using (_pleaseWaitInterruptService.Value.InterruptTemporarily())
            {
                await DispatchHelper.DispatchIfNecessaryAsync(() =>
                {
                    var uriString = uri.ToString().ToLower();

                    using (var scopeManager = ScopeManager <AuthenticationScope> .GetScopeManager(uriString.GetSafeScopeName(), () => new AuthenticationScope()))
                    {
                        var authenticationScope = scopeManager.ScopeObject;

                        var credentialsPrompter = new CredentialsPrompter(_configurationService)
                        {
                            Target   = uriString,
                            UserName = string.Empty,
                            Password = string.Empty,
                            AllowStoredCredentials = !previousCredentialsFailed,
                            ShowSaveCheckBox       = true,
                            WindowTitle            = "Credentials required",
                            MainInstruction        = "Credentials are required to access this feed",
                            Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri),
                            IsAuthenticationRequired = authenticationScope.CanPromptForAuthentication
                        };

                        authenticationScope.HasPromptedForAuthentication = true;

                        result = credentialsPrompter.ShowDialog();
                        if (result ?? false)
                        {
                            credentials.UserName = credentialsPrompter.UserName;
                            credentials.Password = credentialsPrompter.Password;
                        }
                        else
                        {
                            credentials.StoreCredentials = false;
                        }
                    }
                });
            }

            if (result ?? false)
            {
                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName);

                return(credentials);
            }

            Log.Debug("Failed to request credentials for '{0}'", uri);

            return(null);
        }
        public async Task<AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed)
        {
            Log.Debug("Requesting credentials for '{0}'", uri);

            bool? result = null;

            var credentials = new AuthenticationCredentials(uri);

            using (PleaseWaitInterruptService.InterruptTemporarily())
            {
                await DispatchHelper.DispatchIfNecessaryAsync(() =>
                {
                    var uriString = uri.ToString().ToLower();

                    var credentialsPrompter = new CredentialsPrompter
                    {
                        Target = uriString,
                        UserName = string.Empty,
                        Password = string.Empty,
                        AllowStoredCredentials = !previousCredentialsFailed,
                        ShowSaveCheckBox = true,
                        WindowTitle = "Credentials required",
                        MainInstruction = "Credentials are required to access this feed",
                        Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri),
                        IsAuthenticationRequired = _authenticationSilencerService.IsAuthenticationRequired??true
                    };

                    result = credentialsPrompter.ShowDialog();
                    if (result ?? false)
                    {
                        credentials.UserName = credentialsPrompter.UserName;
                        credentials.Password = credentialsPrompter.Password;
                    }
                });
            }

            if (result ?? false)
            {
                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName);

                return credentials;
            }

            Log.Debug("Failed to request credentials for '{0}'", uri);

            return null;
        }
Example #4
0
        public async Task <AuthenticationCredentials> GetCredentialsAsync(Uri uri, bool previousCredentialsFailed)
        {
            Log.Debug("Requesting credentials for '{0}'", uri);

            bool?result = null;

            var credentials = new AuthenticationCredentials(uri);

            using (PleaseWaitInterruptService.InterruptTemporarily())
            {
                await DispatchHelper.DispatchIfNecessaryAsync(() =>
                {
                    var uriString = uri.ToString().ToLower();

                    var credentialsPrompter = new CredentialsPrompter
                    {
                        Target   = uriString,
                        UserName = string.Empty,
                        Password = string.Empty,
                        AllowStoredCredentials = !previousCredentialsFailed,
                        ShowSaveCheckBox       = true,
                        WindowTitle            = "Credentials required",
                        MainInstruction        = "Credentials are required to access this feed",
                        Content = string.Format("In order to continue, please enter the credentials for {0} below.", uri),
                        IsAuthenticationRequired = _authenticationSilencerService.IsAuthenticationRequired ?? true
                    };

                    result = credentialsPrompter.ShowDialog();
                    if (result ?? false)
                    {
                        credentials.UserName = credentialsPrompter.UserName;
                        credentials.Password = credentialsPrompter.Password;
                    }
                });
            }

            if (result ?? false)
            {
                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentials.UserName);

                return(credentials);
            }

            Log.Debug("Failed to request credentials for '{0}'", uri);

            return(null);
        }
        public async Task <CredentialResponse> GetAsync(Uri uri, IWebProxy proxy, CredentialRequestType type, string message, bool isRetry, bool nonInteractive, CancellationToken cancellationToken)
        {
            if (isRetry)
            {
                Log.Debug($"Retrying to request credentials for '{uri}'");
            }
            else
            {
                Log.Debug($"Requesting credentials for '{uri}'");
            }

            bool?result = null;

            var uriString = uri.ToString().ToLower();

            var credentialsPrompter = new CredentialsPrompter(_configurationService)
            {
                Target = uriString,
                AllowStoredCredentials = !isRetry && _canAccessStoredCredentials,
                ShowSaveCheckBox       = true,
                WindowTitle            = "Credentials required",
                MainInstruction        = "Credentials are required to access this feed",
                Content = message,
                IsAuthenticationRequired = true
            };

            result = credentialsPrompter.ShowDialog();

            if (result ?? false)
            {
                //creating success response

                Log.Debug("Successfully requested credentials for '{0}' using user '{1}'", uri, credentialsPrompter.UserName);

                //creating network credentials
                var nugetCredentials = new NetworkCredential(credentialsPrompter.UserName, credentialsPrompter.Password);

                var response = new CredentialResponse(nugetCredentials);

                return(response);
            }
            else
            {
                Log.Debug("Failed to request credentials for '{0}'", uri);
                return(new CredentialResponse(CredentialStatus.UserCanceled));
            }
        }