googleapis / googleapis/google-cloud-rust
User Guide - Auth - sharing credentials
- Dominant language
- Rust
- Stars
- 955
- Forks
- 144
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 279
Description
We might be better off planning all chapters of the auth user guide at once. But this is something I think we will want, and I don't want to forget it.
Consider this code:
```rs
let foo = FooClient::new();
let bar = BarClient::new();
```
Observation: Foo and Bar clients each have constructed a default credential, independently. They will duplicate work to get and return tokens. That is the cost of convenience in a constructor.
Where performance/efficiency matters, applications are advised to share credentials across clients. Cloned Credentials will share the caching mechanism.
```rs
let creds = create_access_token_credentials();
let foo = FooClient::new_with_config(ClientConfig::new().set_credentials(creds.clone()));
let bar = BarClient::new_with_config(ClientConfig::new().set_credentials(creds));
```
Contributor guide
Assessment
This issue has not been assessed yet.