docs]
rust-goauth [Crate for using OAuth 2.0 with Server to Server Applications for Google Cloud Engine, with tentative support for all supported Scopes. Supports sync or async requests via Futures.
Provides a serialisable Token struct for use in other applications that require authenticated interactions with Google Cloud.
Usage
#[macro_use]
extern crate log;
use goauth::auth::JwtClaims;
use goauth::scopes::Scope;
use goauth::{get_token, get_token_blocking, GoErr};
use goauth::credentials::Credentials;
use smpl_jwt::{RSAKey, Jwt};
fn main() -> Result<(), GoErr>{
let token_url = "https://www.googleapis.com/oauth2/v4/token";
let iss = "<some-iss>"; // https://developers.google.com/identity/protocols/OAuth2ServiceAccount
let credentials = Credentials::from_file("dummy_credentials_file_for_tests.json").unwrap();
let claims = JwtClaims::new(String::from(iss),
&Scope::DevStorageReadWrite,
String::from(token_url),
None, None);
let jwt = Jwt::new(claims, credentials.rsa_key().unwrap(), None);
// Use async
let token = async {
match get_token(&jwt, &credentials).await {
Ok(token) => token,
Err(e) => panic!(e)
}
};
// Or sync
let token = get_token_blocking(&jwt, &credentials)?;
Ok(())
}