Skip to content

[PECOBLR-2160] feat(rust/oauth): U2M and M2M providers with callback server#322

Open
vikrantpuppala wants to merge 16 commits intoadbc-drivers:mainfrom
vikrantpuppala:stack/pr-u2m-provider
Open

[PECOBLR-2160] feat(rust/oauth): U2M and M2M providers with callback server#322
vikrantpuppala wants to merge 16 commits intoadbc-drivers:mainfrom
vikrantpuppala:stack/pr-u2m-provider

Conversation

@vikrantpuppala
Copy link
Collaborator

@vikrantpuppala vikrantpuppala commented Mar 8, 2026

🥞 Stacked PR

Use this link to review incremental changes.


Summary

Implements both OAuth authentication providers and wires them into Database::new_connection():

  • CallbackServer — lightweight TCP server on localhost that captures OAuth redirect callbacks, validates CSRF state, extracts authorization codes
  • AuthorizationCodeProvider (U2M) — full authorization code + PKCE flow: browser launch, callback capture, token exchange, refresh token support with disk caching
  • ClientCredentialsProvider (M2M) — client credentials grant with TokenStore-managed lifecycle (initial fetch, stale refresh, expiry re-auth)
  • Database::new_connection() — creates the appropriate AuthProvider based on AuthConfig (PAT, token passthrough, M2M, or U2M)
  • Removed stale #[allow(dead_code)] annotations and unused fetch_token duplicate

Key files

  • src/auth/oauth/callback.rs — OAuth redirect callback server
  • src/auth/oauth/u2m.rs — U2M authorization code + PKCE provider
  • src/auth/oauth/m2m.rs — M2M client credentials provider
  • src/database.rs — auth provider creation in new_connection()

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-u2m-provider branch from e305f9a to 36b5072 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