Crates.io | github_auth |
lib.rs | github_auth |
version | 0.8.0 |
source | src |
created_at | 2018-05-03 13:07:31.755149 |
updated_at | 2020-09-27 15:31:05.439316 |
description | Authenticate with GitHub from the command line. |
homepage | |
repository | https://github.com/yoshuawuyts/github_auth |
max_upload_size | |
id | 63561 |
size | 96,532 |
Authenticate with GitHub from the command line. Caches the authentication token so that future interactions just work.
extern crate github_auth;
use github_auth::{Authenticator, Scope};
let auth = Authenticator::builder("github_auth main example".into())
.scope(Scope::PublicRepo)
.build();
let token = auth.auth().unwrap();
println!("{:?}", token);
let location = auth.location();
println!("Token stored at: {:?}", location);
This dialog is only required to generate a valid token. Once a valid token is created, it will no longer be shown.
GitHub username: my_name
GitHub password:
GitHub OTP (optional): 5678
Once you've acquired an access token, you can use it to authenticate. Here's how to authenticate with the reqwest crate.
extern crate github_auth;
extern crate reqwest;
use github_auth::Authenticator;
use reqwest::{
header::{Authorization, Headers, UserAgent},
Client,
};
let auth = Authenticator::new("my_example_app");
let token = auth.auth().unwrap();
let mut headers = Headers::new();
headers.set(Authorization(format!("token {}", token.as_str())).to_owned());
headers.set(UserAgent::new("my_app"));
let url = "https://api.github.com/user";
let mut res = client.get(&url).headers(headers).send()?;
println!("{:?}", res.status());
$ cargo add github_auth
MIT OR Apache-2.0