Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readme example #277

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading