From 6035d8bb24f0d8587f272300d4f7dff6bdc5fa57 Mon Sep 17 00:00:00 2001 From: bouzuya Date: Sun, 16 Jun 2024 14:01:34 +0900 Subject: [PATCH] Fix readme example (#277) * Bump google-cloud-token from 0.1.1 to 0.1.2 * Fix readme example --- foundation/auth/Cargo.toml | 2 +- foundation/auth/README.md | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/foundation/auth/Cargo.toml b/foundation/auth/Cargo.toml index 91457806..1d085fa2 100644 --- a/foundation/auth/Cargo.toml +++ b/foundation/auth/Cargo.toml @@ -21,7 +21,7 @@ home = "0.5" urlencoding = "2.1" tokio = { version = "1.32", features = ["fs"] } google-cloud-metadata = { version = "0.5.0", path = "../metadata" } -google-cloud-token = { version = "0.1.1", path = "../token" } +google-cloud-token = { version = "0.1.2", path = "../token" } base64 = "0.21" time = "0.3" diff --git a/foundation/auth/README.md b/foundation/auth/README.md index 71d27c9e..b513f7be 100644 --- a/foundation/auth/README.md +++ b/foundation/auth/README.md @@ -9,15 +9,17 @@ Google Cloud Platform server application authentication library. ```toml [dependencies] google-cloud-auth = +google-cloud-token = "0.1.2" ``` ## Quickstart ```rust -use google_cloud_auth::*; - #[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", @@ -30,16 +32,17 @@ async fn main() -> Result<(), error::Error> { // scopes is required only for service account Oauth2 // https://developers.google.com/identity/protocols/oauth2/service-account scopes: Some(&scopes), - sub: None + sub: None, }; - let ts = create_token_source(config).await?; + let tsp = DefaultTokenSourceProvider::new(config).await?; + let ts = tsp.token_source(); let token = ts.token().await?; - println!("token is {}",token.access_token); + println!("token is {}", token); Ok(()) } ``` -`create_token_source`looks for credentials in the following places, +`DefaultTokenSourceProvider::new(config)` looks for credentials in the following places, preferring the first location found: 1. A JSON file whose path is specified by the @@ -59,7 +62,7 @@ preferring the first location found: ## Supported Workload Identity -https://cloud.google.com/iam/docs/workload-identity-federation + - [x] AWS - [ ] Azure Active Directory