Exemple #1
0
        public bool TryGetPassphrase(string username, out IGitCredential gitCredential)
        {
            string message = "Enter passphrase:";

            // The key in Windows Credentials Manager
            string targetKey = $"GitMind:pswd:{username}";

            return(TryGet(null, username, targetKey, message, true, out gitCredential));
        }
Exemple #2
0
        public bool TryGetCredential(string url, string username, out IGitCredential gitCredential)
        {
            string message = $"Enter credentials for {url}";

            // The key in Windows Credentials Manager
            string targetKey = $"GitMind:{url}";

            return(TryGet(url, username, targetKey, message, false, out gitCredential));
        }
Exemple #3
0
        public string HandleGetCredential(string seeking, string totalUrl)
        {
            // This function will be called 2 times. The first time is a request for UserName.
            // However, we try to get both user name and password and then store credential in memory
            // so the password can be returned in the second call without bothering the user again.
            // The total url may contain some parts (user name) of the credential, lets try extract that.
            ParseUrl(totalUrl, out string url, out string parsedUsername);

            if (seeking.SameIc("Username"))
            {
                // First call requesting the UserName
                IsCredentialRequested = true;
                TargetUri             = url;

                string username = Username ?? parsedUsername;

                // Try get cached credential och show credential dialog
                if (credentialService.TryGetCredential(url, username, out gitCredential))
                {
                    TargetUri = url;
                    Username  = gitCredential.Username;
                    Log.Debug($"Response: {Username}");
                    return(Username);
                }

                IsAskPassCanceled = true;
                return(null);
            }
            else if (seeking.SameIc("Password"))
            {
                // Second call requesting the Password. Lets ensure it is for the stored Username in previous call
                if (gitCredential != null &&
                    url == gitCredential.Url &&
                    parsedUsername == gitCredential.Username)
                {
                    string password = gitCredential.Password;
                    Log.Debug($"Response: <password for {parsedUsername}>");
                    return(password);
                }
            }
            else
            {
                Log.Debug("Invalid request");
                gitCredential = null;
            }

            Log.Debug("No response");
            return(null);
        }
Exemple #4
0
        private bool TryGet(
            string url,
            string username,
            string targetKey,
            string message,
            bool isNameReadonly,
            out IGitCredential gitCredential)
        {
            CredentialsDialog dialog = null;

            UiThread.Run(() => dialog = ShowDialog(targetKey, username, message, isNameReadonly));

            if (dialog != null)
            {
                gitCredential = new GitCredential(dialog, url);
                return(true);
            }

            Log.Debug("Credentials dialog canceled");
            gitCredential = null;
            return(false);
        }
Exemple #5
0
        public void SetDialogConfirm(IGitCredential gitCredential, bool isConfirmed)
        {
            try
            {
                CredentialsDialog credentialsDialog = (gitCredential as GitCredential)?.Dialog;

                if (credentialsDialog == null)
                {
                    return;
                }

                if (!isConfirmed)
                {
                    // Provided credentials where not valid
                    Track.Event("CredentialsDialog-Denied");
                    credentialsDialog.Confirm(false);
                    bool isDeleted = credentialsDialog.Delete();
                    Log.Debug($"Deleted: {isDeleted}");
                }
                else if (credentialsDialog.SaveChecked)
                {
                    // Provided credentials where valid and user want them to be cached
                    Track.Event("CredentialsDialog-Confirmed");
                    credentialsDialog.Confirm(true);
                }
                else
                {
                    // User did not want valid credentials to be cached
                    Track.Event("CredentialsDialog-NotCached");
                }
            }
            catch (ApplicationException e)
            {
                Log.Exception(e, "");
            }
        }