https://github.com/kayagokalp/git2_auth
A small library to provide easy to use callback handler to authenticate with git2-rs
https://github.com/kayagokalp/git2_auth
authentication git git2-rs libgit2 rust ssh
Last synced: 12 months ago
JSON representation
A small library to provide easy to use callback handler to authenticate with git2-rs
- Host: GitHub
- URL: https://github.com/kayagokalp/git2_auth
- Owner: kayagokalp
- License: mit
- Created: 2023-03-06T15:16:33.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T18:32:54.000Z (about 3 years ago)
- Last Synced: 2025-01-26T00:11:18.009Z (about 1 year ago)
- Topics: authentication, git, git2-rs, libgit2, rust, ssh
- Language: Rust
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git2_auth
An authentication handler to be used with `git2_rs`. An example usage can be seen below. I used the following repos:
- [Cargo](https://github.com/rust-lang/cargo/blob/f72f8a87c8c6ec05a3706ef9987899cd105db622/src/cargo/sources/git/utils.rs#L450-L718)
- [git2_credentials](https://github.com/davidB/git2_credentials)
## TODO
- [ ] User defined ssh handlers
- [ ] User provided username trials
## Example Usage
```rust
// Setup remote callbacks
let mut callback = git2::RemoteCallbacks::new();
let config = git2::Config::open_default().unwrap();
// Setup authentication handler
let mut auth_handler = AuthHandler::default_with_config(config);
callback.credentials(move |url, username, allowed| {
auth_handler.handle_callback(url, username, allowed)
});
// Create fetch options
let mut fetch_options = git2::FetchOptions::new();
fetch_options
.remote_callbacks(callback)
.download_tags(git2::AutotagOption::All)
.update_fetchhead(true);
// Clone the repo
git2::build::RepoBuilder::new()
.branch("master")
.fetch_options(fetch_options)
.clone("git@github.com:kayagokalp/git2_auth.git", dir.as_ref())
.unwrap();
```
## License
[MIT](https://choosealicense.com/licenses/mit/)