1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! # gcloud-identity-token
//!
//! A Rust library for obtaining and caching Google OAuth2 tokens for use with
//! Google Cloud APIs.
//!
//! This crate handles the entire OAuth 2.0 Authorization Code flow:
//! - Launching a browser to log in
//! - Receiving and exchanging authorization codes
//! - Saving access, refresh, and ID tokens
//! - Securely caching them using the system keyring or a local file
//!
//! ## Features
//! - Secure keyring-backed token storage (per Google user)
//! - File-based cache via `GCLOUD_IDENTITY_TOKEN_PATH` override
//! - Fully async support with `reqwest` + `tokio`
//! - Intelligent refresh with expiry tracking
//!
//! ## Example
//!
//! ```rust,no_run
//! use anyhow::Result;
//! use gcloud_identity_token::{auth::get_token, config::load_creds};
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let creds = load_creds()?;
//! let token = get_token(&creds).await?;
//! println!("Access Token: {}", token.access_token);
//! println!("ID Token: {}", token.id_token);
//! Ok(())
//! }
//! ```
//!
//! ## Environment Variables
//! - `GCLOUD_IDENTITY_TOKEN_PATH` — path to file-based token cache
//! - `DISPLAY` / `WAYLAND_DISPLAY` — if unset, triggers headless login flow
//!
//! ## Modules
/// Authorization flow and token refresh logic.
/// Browser launching and redirect capture logic.
/// Token cache handling (keyring and file-based).
/// Configuration structures and token types.
/// Shared utilities like port picking.