rust-goauth [docs]
Crate for using OAuth 2.0 with Server to Server Applications for Google Cloud Engine, with tentative support for all supported Scopes.
Provides a serialisable Token struct for use in other applications that require authenticated interactions with Google Cloud.
extern crate smpl_jwt;
extern crate goauth;
#[macro_use]
extern crate log;
use goauth::auth::JwtClaims;
use goauth::scopes::Scope;
use goauth::get_token;
use smpl_jwt::{RSAKey, Jwt};
fn main() {
let token_url = "https://www.googleapis.com/oauth2/v4/token";
let iss = "some_iss"; // https://developers.google.com/identity/protocols/OAuth2ServiceAccount
let private_key_file = "random_rsa_for_testing";
let claims = JwtClaims::new(String::from(iss),
Scope::DevStorageReadWrite,
String::from(token_url),
None, None);
let key = match RSAKey::from_pem(private_key_file) {
Ok(x) => x,
Err(e) => panic!("{}", e)
};
let jwt = Jwt::new(claims, key, None);
match get_token(&jwt, None) {
Ok(x) => debug!("{}", x),
Err(e) => debug!("{}", e)
};
}