[][src]Function goauth::get_token

pub async fn get_token<'_, '_>(
    jwt: &'_ Jwt<JwtClaims>,
    credentials: &'_ Credentials
) -> Result<Token>

Async get Token which can be used to authenticate further request

Example

extern crate smpl_jwt;
extern crate goauth;
#[macro_use]
extern crate log;
extern crate futures;

use goauth::auth::JwtClaims;
use goauth::scopes::Scope;
use goauth::credentials::Credentials;
use goauth::GoErr;
use goauth::get_token;
use smpl_jwt::Jwt;
use futures::future::Future;


fn main() -> Result<(), GoErr> {

  let credentials = Credentials::from_file("dummy_credentials_file_for_tests.json").unwrap();

  let claims = JwtClaims::new(credentials.iss(),
                             &Scope::DevStorageReadWrite,
                             credentials.token_uri(),
                             None, None);

  let jwt = Jwt::new(claims, credentials.rsa_key().unwrap(), None);
  async {
    match get_token(&jwt, &credentials).await {
        Ok(token) => println!("{}", token),
        Err(_) => panic!("An error occurred, somewhere in there, try debugging with `get_token_with_creds`")
    }
  };
  Ok(())
}