how can I fallback authentication from ssh to plain username and password if no ssh key valid found
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the credentials callback and the git2::Cred::userpass_plaintext call shown in the issue, then inspect how the git@... URL and allowed credential types are handled. Reproduce the username-mismatch error and determine whether the supported behavior should be documented or covered by a regression test for overriding URL-based authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- authentication
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100