Crates.io | google-cloud-auth |
lib.rs | google-cloud-auth |
version | 0.17.1 |
source | src |
created_at | 2021-11-26 05:25:33.035715 |
updated_at | 2024-09-22 12:21:05.12022 |
description | Google Cloud Platform server application authentication library. |
homepage | |
repository | https://github.com/yoshidan/google-cloud-rust/tree/main/foundation/auth |
max_upload_size | |
id | 487907 |
size | 84,749 |
Google Cloud Platform server application authentication library.
[dependencies]
google-cloud-auth = <version>
google-cloud-token = "0.1.2"
#[tokio::main]
async fn main() -> Result<(), error::Error> {
use google_cloud_auth::{project::Config, token::DefaultTokenSourceProvider};
use google_cloud_token::TokenSourceProvider as _;
let audience = "https://spanner.googleapis.com/";
let scopes = [
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/spanner.data",
];
let config = Config {
// audience is required only for service account jwt-auth
// https://developers.google.com/identity/protocols/oauth2/service-account#jwt-auth
audience: Some(audience),
// scopes is required only for service account Oauth2
// https://developers.google.com/identity/protocols/oauth2/service-account
scopes: Some(&scopes),
sub: None,
};
let tsp = DefaultTokenSourceProvider::new(config).await?;
let ts = tsp.token_source();
let token = ts.token().await?;
println!("token is {}", token);
Ok(())
}
DefaultTokenSourceProvider::new(config)
looks for credentials in the following places,
preferring the first location found:
https://cloud.google.com/iam/docs/workload-identity-federation