Skip to content

Commit

Permalink
Fix readme example (#277)
Browse files Browse the repository at this point in the history
* Bump google-cloud-token from 0.1.1 to 0.1.2

* Fix readme example
  • Loading branch information
bouzuya authored Jun 16, 2024
1 parent df74291 commit 6035d8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion foundation/auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 10 additions & 7 deletions foundation/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ Google Cloud Platform server application authentication library.
```toml
[dependencies]
google-cloud-auth = <version>
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",
Expand All @@ -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
Expand All @@ -59,7 +62,7 @@ preferring the first location found:

## Supported Workload Identity

https://cloud.google.com/iam/docs/workload-identity-federation
<https://cloud.google.com/iam/docs/workload-identity-federation>

- [x] AWS
- [ ] Azure Active Directory
Expand Down

0 comments on commit 6035d8b

Please sign in to comment.