private LibGit2Sharp.Credentials CredentialsHandler(string url, string usernameFromUrl, SupportedCredentialTypes types)
 {
     if (string.IsNullOrEmpty(this.repository.UserName))
     {
         if (types.HasFlag(SupportedCredentialTypes.Default))
         {
             this.log.LogDebug($"Connecting with default credentials...");
             return(new DefaultCredentials());
         }
         else
         {
             this.log.LogDebug($"Connecting anonymously...");
             return(null);
         }
     }
     else
     {
         this.log.LogDebug($"Connecting as user '{this.repository.UserName}'...");
         return(new SecureUsernamePasswordCredentials
         {
             Username = this.repository.UserName,
             Password = this.repository.Password
         });
     }
 }
        private Credentials BuildCredentialsProvider(string url, string fromUrl, SupportedCredentialTypes types, FlatFileCmsGitOptions options)
        {
            if (types.HasFlag(SupportedCredentialTypes.Ssh))
            {
                string username = fromUrl.IsNullOrWhiteSpace() ? "git" : fromUrl;

                return(new SshUserKeyCredentials
                {
                    Username = username,
                    PublicKey = options.PublicKey,
                    PrivateKey = options.PrivateKey,
                    Passphrase = options.Passphrase
                });
            }

            if (types.HasFlag(SupportedCredentialTypes.UsernamePassword))
            {
                var repoUri  = new Uri(url);
                var userInfo = repoUri.UserInfo.Split(':');

                if (!userInfo.Any())
                {
                    return(new DefaultCredentials());
                }

                string username = userInfo[0];
                string password = userInfo.ElementAtOrDefault(1) ?? string.Empty;

                return(new UsernamePasswordCredentials
                {
                    Username = username,
                    Password = password
                });
            }

            return(new DefaultCredentials());
        }
Beispiel #3
0
        public XwtCredentialsDialog(string uri, SupportedCredentialTypes supportedCredential, Credentials credentials)
        {
            Title     = GettextCatalog.GetString("Git Credentials");
            Resizable = false;

            Width = 500;

            var mainContainer = new VBox();

            Content = mainContainer;

            //Credentials
            var credentialsLabel = new Label(GettextCatalog.GetString("Credentials required for the repository:"))
            {
                Wrap = WrapMode.Word
            };

            mainContainer.PackStart(credentialsLabel);

            var credentialValue = new Label {
                Markup = string.Format(credentialMarkupFormat, uri),
                Wrap   = WrapMode.Word
            };

            mainContainer.PackStart(credentialValue);

            if (supportedCredential.HasFlag(SupportedCredentialTypes.UsernamePassword))
            {
                credentialsWidget = new UserPasswordCredentialsWidget(credentials as UsernamePasswordCredentials);
            }
            else
            {
                credentialsWidget = new SshCredentialsWidget(credentials as SshUserKeyCredentials);
            }

            credentialsWidget.CredentialsChanged += OnCredentialsChanged;
            mainContainer.PackStart(credentialsWidget.Widget, marginTop: InputContainerContainerSpacing);

            //Buttons
            Buttons.Add(new DialogButton(Command.Cancel));
            Buttons.Add(okButton = new DialogButton(Command.Ok));
            DefaultCommand       = Command.Ok;

            okButton.Sensitive = credentialsWidget.CredentialsAreValid;
        }