Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I fallback authentication from ssh to plain username and password if no ssh key valid found #888

Open
Masber opened this issue Oct 5, 2022 · 0 comments

Comments

@Masber
Copy link

Masber commented Oct 5, 2022

I would like to overwrite the default authentication based on remote url. For instance, I have a url like git@... which means git2-rs will expect to authenticate through ssh with user git. I want to be able to login using plain username and password instead like the example below.

I tried the following:

        cb.credentials(|_url, _username_from_url, _allowed_types| {
            log::debug!("url is: {}", _url);
            log::debug!("username from url is: {}", _username_from_url.unwrap_or("Not defined"));
            log::debug!("allowed types are: {:#?}", _allowed_types);
                        
            let mut cred = git2::Cred::userpass_plaintext("username", "password"); an https address 'url = https://git.cscs.ch/msopena/manta.git' makes library to switch to CredentialType::USER_PASS_PLAINTEXT
            
            let cred_aux: git2::Cred = cred.unwrap();

            log::debug!("credentials type: {}", &cred_aux.credtype());
            log::debug!("credentials username: {}", &cred_aux.has_username());

            Ok(cred_aux)
        });

and this is what I get

[2022-10-05T16:22:29Z DEBUG manta::git2_rs_utils::local] url is: git@...
[2022-10-05T16:22:29Z DEBUG manta::git2_rs_utils::local] username from url is: git
[2022-10-05T16:22:29Z DEBUG manta::git2_rs_utils::local] allowed types are: USER_PASS_PLAINTEXT | SSH_KEY | SSH_MEMORY | SSH_CUSTOM
[2022-10-05T16:22:29Z DEBUG manta::git2_rs_utils::local] credentials type: 1
[2022-10-05T16:22:29Z DEBUG manta::git2_rs_utils::local] credentials username: true
Error: Error { code: -1, klass: 23, message: "username does not match previous request" }

Any idea how can I force the git2-rs to use a different authentication type ignoring the username in the url?

@Masber Masber changed the title how can I overwrite the url username and change authentication how can I fallback authentication from ssh to plain username and password if no ssh key valid found Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant