Skip to content

[PECOBLR-2158] feat(rust/oauth): Token primitives, OIDC discovery, cache and token store#320

Open
vikrantpuppala wants to merge 10 commits intoadbc-drivers:mainfrom
vikrantpuppala:stack/pr-oauth-foundation
Open

[PECOBLR-2158] feat(rust/oauth): Token primitives, OIDC discovery, cache and token store#320
vikrantpuppala wants to merge 10 commits intoadbc-drivers:mainfrom
vikrantpuppala:stack/pr-oauth-foundation

Conversation

@vikrantpuppala
Copy link
Collaborator

@vikrantpuppala vikrantpuppala commented Mar 8, 2026

🥞 Stacked PR

Use this link to review incremental changes.


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 dependenciesoauth2, 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.rsOAuthToken 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

vikrantpuppala and others added 9 commits March 7, 2026 08:48
Design for OAuth 2.0 authentication in the Rust ADBC driver covering
Authorization Code + PKCE (U2M) and Client Credentials (M2M) flows,
including token refresh state machine, file-based caching, and OIDC
discovery.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use oauth2 crate for PKCE, token exchange, client credentials,
  and refresh token flows. Eliminates hand-rolled pkce.rs module.
- Reuse DatabricksHttpClient for token endpoint calls via
  execute_without_auth(), giving unified retry/timeout/pooling.
- Two-phase initialization: HTTP client created first, auth provider
  set later via OnceLock (matching SeaClient's reader_factory pattern).
- OAuth providers route token requests through the shared HTTP client
  with a custom oauth2 HTTP function adapter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add AuthMechanism enum: 0=Pat, 11=OAuth (matches ODBC AuthMech)
- Add AuthFlow enum: 0=TokenPassthrough, 1=ClientCredentials, 2=Browser
  (matches ODBC Auth_Flow)
- Both mechanism and flow are mandatory, no auto-detection
- Accept numeric values only, parsed via TryFrom
- Use unified DatabricksHttpClient with two-phase init
- Adopt oauth2 crate for protocol-level operations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes:
- databricks.oauth.token_endpoint -> databricks.auth.token_endpoint
- Config type Int/String -> Int (numeric only)
- Clarify oauth2 HTTP adapter needs thin conversion layer
- Architecture diagram shows M2M/U2M using execute_without_auth()
- Token passthrough (flow=0) documents no auto-refresh
- Stale threshold uses initial_TTL computed once at acquisition
- Deduplicate http.rs changes (reference Concurrency section)

Test strategy additions:
- Wiremock integration tests for full M2M flow with mocked HTTP
- Database config validation tests for enum parsing and new_connection
- HTTP client two-phase init tests for OnceLock lifecycle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3-task breakdown covering foundation + HTTP client changes,
M2M provider, and U2M provider with full test coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vikrantpuppala vikrantpuppala force-pushed the stack/pr-oauth-foundation branch from e0a0fdc to fe4a411 Compare March 9, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant