{"id":17209340,"url":"https://github.com/de-vri-es/auth-git2-rs","last_synced_at":"2025-07-20T07:06:01.608Z","repository":{"id":186765604,"uuid":"675731593","full_name":"de-vri-es/auth-git2-rs","owner":"de-vri-es","description":"Easy authentication for git2 in Rust","archived":false,"fork":false,"pushed_at":"2025-02-13T20:39:01.000Z","size":93,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T05:17:21.098Z","etag":null,"topics":["authentication","git","hacktoberfest","libgit2","rust","ssh"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/de-vri-es.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-07T15:38:43.000Z","updated_at":"2025-04-03T08:03:05.000Z","dependencies_parsed_at":"2024-10-15T02:51:24.408Z","dependency_job_id":null,"html_url":"https://github.com/de-vri-es/auth-git2-rs","commit_stats":null,"previous_names":["de-vri-es/auth-git2-rs","de-vri-es/git2-auth-rs"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/de-vri-es%2Fauth-git2-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/de-vri-es%2Fauth-git2-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/de-vri-es%2Fauth-git2-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/de-vri-es%2Fauth-git2-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/de-vri-es","download_url":"https://codeload.github.com/de-vri-es/auth-git2-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790616,"owners_count":21162056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","git","hacktoberfest","libgit2","rust","ssh"],"created_at":"2024-10-15T02:51:21.766Z","updated_at":"2025-04-13T22:31:28.582Z","avatar_url":"https://github.com/de-vri-es.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# auth-git2\n\nEasy authentication for [`git2`].\n\nAuthentication with [`git2`] can be quite difficult to implement correctly.\nThis crate aims to make it easy.\n\n## Features\n\n* Has a small dependency tree.\n* Can query the SSH agent for private key authentication.\n* Can get SSH keys from files.\n* Can prompt the user for passwords for encrypted SSH keys.\n    * Only supported for OpenSSH private keys.\n* Can query the git credential helper for usernames and passwords.\n* Can use pre-provided plain usernames and passwords.\n* Can prompt the user for credentials as a last resort.\n* Allows you to fully customize all user prompts.\n\nThe default user prompts will:\n* Use the git `askpass` helper if it is configured.\n* Fall back to prompting the user on the terminal if there is no `askpass` program configured.\n* Skip the prompt if there is also no terminal available for the process.\n\n## Creating an authenticator and enabling authentication mechanisms\n\nYou can create use [`GitAuthenticator::new()`] (or [`default()`][`GitAuthenticator::default()`]) to create a ready-to-use authenticator.\nUsing one of these constructors will enable all supported authentication mechanisms.\nYou can still add more private key files from non-default locations to try if desired.\n\nYou can also use [`GitAuthenticator::new_empty()`] to create an authenticator without any authentication mechanism enabled.\nThen you can selectively enable authentication mechanisms and add custom private key files.\n\n## Using the authenticator\n\nFor the most flexibility, you can get a [`git2::Credentials`] callback using the [`GitAuthenticator::credentials()`] function.\nYou can use it with any git operation that requires authentication.\nDoing this gives you full control to set other options and callbacks for the git operation.\n\nIf you don't need to set other options or callbacks, you can also use the convenience functions on [`GitAuthenticator`].\nThey wrap git operations with the credentials callback set:\n\n* [`GitAuthenticator::clone_repo()`]\n* [`GitAuthenticator::fetch()`]\n* [`GitAuthenticator::download()`]\n* [`GitAuthenticator::push()`]\n\n## Customizing user prompts\n\nAll user prompts can be fully customized by calling [`GitAuthenticator::set_prompter()`].\nThis allows you to override the way that the user is prompted for credentials or passphrases.\n\nIf you have a fancy user interface, you can use a custom prompter to integrate the prompts with your user interface.\n\n## Example: Clone a repository\n\n```rust\nuse auth_git2::GitAuthenticator;\nuse std::path::Path;\n\nlet url = \"https://github.com/de-vri-es/auth-git2-rs\";\nlet into = Path::new(\"/tmp/dyfhxoaj/auth-git2-rs\");\n\nlet auth = GitAuthenticator::default();\nlet mut repo = auth.clone_repo(url, into);\n```\n\n## Example: Clone a repository with full control over fetch options\n\n```rust\nuse auth_git2::GitAuthenticator;\nuse std::path::Path;\n\nlet auth = GitAuthenticator::default();\nlet git_config = git2::Config::open_default()?;\nlet mut repo_builder = git2::build::RepoBuilder::new();\nlet mut fetch_options = git2::FetchOptions::new();\nlet mut remote_callbacks = git2::RemoteCallbacks::new();\n\nremote_callbacks.credentials(auth.credentials(\u0026git_config));\nfetch_options.remote_callbacks(remote_callbacks);\nrepo_builder.fetch_options(fetch_options);\n\nlet url = \"https://github.com/de-vri-es/auth-git2-rs\";\nlet into = Path::new(\"/tmp/dyfhxoaj/auth-git2-rs\");\nlet mut repo = repo_builder.clone(url, into);\n```\n\n[`git2`]: https://docs.rs/git2\n[`GitAuthenticator`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html\n[`GitAuthenticator::new()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.new\n[`GitAuthenticator::default()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.default\n[`GitAuthenticator::new_empty()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.new_empty\n[`git2::Credentials`]: https://docs.rs/git2/latest/git2/type.Credentials.html\n[`GitAuthenticator::credentials()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.credentials\n[`GitAuthenticator::clone_repo()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.clone_repo\n[`GitAuthenticator::fetch()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.fetch\n[`GitAuthenticator::push()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.push\n[`GitAuthenticator::download()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.download\n[`GitAuthenticator::set_prompter()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.set_prompter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fde-vri-es%2Fauth-git2-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fde-vri-es%2Fauth-git2-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fde-vri-es%2Fauth-git2-rs/lists"}