7 releases

0.4.5 Jun 17, 2024
0.4.4 Mar 21, 2024
0.4.2 Feb 9, 2024
0.4.1 Nov 18, 2023
0.1.0 Dec 16, 2020

#118 in Authentication

Download history 18779/week @ 2024-03-26 16610/week @ 2024-04-02 15276/week @ 2024-04-09 14792/week @ 2024-04-16 14817/week @ 2024-04-23 15723/week @ 2024-04-30 16423/week @ 2024-05-07 15250/week @ 2024-05-14 14463/week @ 2024-05-21 15581/week @ 2024-05-28 14999/week @ 2024-06-04 14106/week @ 2024-06-11 15872/week @ 2024-06-18 15061/week @ 2024-06-25 13834/week @ 2024-07-02 12265/week @ 2024-07-09

59,732 downloads per month
Used in 44 crates (9 directly)


653 lines


This package is a library to assist writing a Cargo credential helper, which provides an interface to store tokens for authorizing access to a registry such as https://crates.io/.

Documentation about credential processes may be found at https://doc.rust-lang.org/nightly/cargo/reference/credential-provider-protocol.html

Example implementations may be found at https://github.com/rust-lang/cargo/tree/master/credential


Create a Cargo project with this as a dependency:

# Add this to your Cargo.toml:

cargo-credential = "0.4"

And then include a main.rs binary which implements the Credential trait, and calls the main function which will call the appropriate method of the trait:

// src/main.rs

use cargo_credential::{Credential, Error};

struct MyCredential;

impl Credential for MyCredential {
    /// implement trait methods here...

fn main() {


Helper library for writing Cargo credential providers.

A credential process should have a struct that implements the Credential trait. The main function should be called with an instance of that struct, such as:

fn main() {

While in the perform function, stdin and stdout will be re-attached to the active console. This allows credential providers to be interactive if necessary.

Error handling


A credential provider may only support some registry URLs. If this is the case and an unsupported index URL is passed to the provider, it should respond with Error::UrlNotSupported. Other credential providers may be attempted by Cargo.


When attempting an Action::Get or Action::Logout, if a credential can not be found, the provider should respond with Error::NotFound. Other credential providers may be attempted by Cargo.


A credential provider might not support all operations. For example if the provider only supports Action::Get, Error::OperationNotSupported should be returned for all other requests.


All other errors go here. The error will be shown to the user in Cargo, including the full error chain using std::error::Error::source.



~119K SLoC