Skip to content

Commit 0eb5ee7

Browse files
feat(rust): OAuth token primitives, OIDC discovery, cache and token store (#320)
## 🥞 Stacked PR Use this [link](https://github.com/adbc-drivers/databricks/pull/320/files) to review incremental changes. - [**stack/pr-oauth-foundation**](#320) [[Files changed](https://github.com/adbc-drivers/databricks/pull/320/files)] - [stack/pr-database-config](#321) [[Files changed](https://github.com/adbc-drivers/databricks/pull/321/files/78b9ec88459f895c76bd1aea99fcb47e5eb94893..164ada04d14660306c7e44dd3d52a7943050aa27)] - [stack/pr-u2m-provider](#322) [[Files changed](https://github.com/adbc-drivers/databricks/pull/322/files/164ada04d14660306c7e44dd3d52a7943050aa27..abc00ced51d89f1a652f78209f692775eba05e73)] - [stack/pr-integration-tests](#323) [[Files changed](https://github.com/adbc-drivers/databricks/pull/323/files/abc00ced51d89f1a652f78209f692775eba05e73..75b18d6c594eeba89a30450152d6d6f672239614)] - [stack/pr-final-validation](#324) [[Files changed](https://github.com/adbc-drivers/databricks/pull/324/files/75b18d6c594eeba89a30450152d6d6f672239614..2d6ccb09e121015aa6a0da6e992529a686bb0f04)] --------- ## Summary Adds the core OAuth token infrastructure used by both U2M and M2M flows: - **`OAuthToken`** — token struct with expiry tracking, stale detection (40s buffer / 50% TTL), and serde support - **OIDC discovery** — fetches `authorization_endpoint` and `token_endpoint` from `/.well-known/oauth-authorization-server` - **`TokenCache`** — file-based persistence at `~/.config/databricks-adbc/oauth/` with SHA-256 hashed filenames and `0o600` permissions - **`TokenStore`** — thread-safe token lifecycle (Empty → Fresh → Stale → Expired) with coordinated refresh via `RwLock` + `AtomicBool` - **Cargo dependencies** — `oauth2`, `sha2`, `dirs`, `serde`, `open` crates - **`DatabricksHttpClient`** — extended with `OnceLock`-based auth provider and `inner()` accessor for the `oauth2` crate ### Key files - `src/auth/oauth/token.rs` — `OAuthToken` struct - `src/auth/oauth/oidc.rs` — OIDC endpoint discovery - `src/auth/oauth/cache.rs` — file-based token cache - `src/auth/oauth/token_store.rs` — token lifecycle state machine - `src/client/http.rs` — HTTP client auth provider integration
1 parent 5fe4084 commit 0eb5ee7

File tree

15 files changed

+2342
-115
lines changed

15 files changed

+2342
-115
lines changed

rust/Cargo.lock

Lines changed: 459 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,17 @@ thiserror = "2"
6767
# Arrow C Data Interface for metadata FFI
6868
arrow = { version = "57", optional = true, default-features = false, features = ["ffi"] }
6969

70+
# OAuth dependencies
71+
oauth2 = "5" # OAuth 2.0 protocol operations (PKCE, token exchange, client credentials)
72+
sha2 = "0.10" # SHA-256 for token cache key generation
73+
open = "5" # Browser launch for interactive OAuth flows
74+
dirs = "5" # Cross-platform config directory (~/.config/)
75+
7076
[dev-dependencies]
7177
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
7278
wiremock = "0.6"
7379
adbc_driver_manager = "0.22"
80+
tempfile = "3"
7481

7582
[features]
7683
default = []

rust/about.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
accepted = [
1717
"Apache-2.0",
1818
"BSD-3-Clause",
19+
"CDLA-Permissive-2.0",
1920
"ISC",
2021
"MIT",
22+
"MPL-2.0",
2123
"Unicode-3.0",
2224
"Unlicense",
2325
]

rust/src/auth/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
pub mod oauth;
1818
pub mod pat;
1919

20-
pub use oauth::OAuthCredentials;
2120
pub use pat::PersonalAccessToken;
2221

2322
use crate::error::Result;

rust/src/auth/oauth.rs

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)