Repository navigation
Commit 136fd86
authored
fix(pyo3): default U2M scopes to ["sql","offline_access"] for the default Python client (#153)
## Summary
- The pyo3 binding overrides the U2M `client_id` default to
`databricks-sql-python` (to match the Thrift connector's OAuth app
identity) but forwards `scopes=None` unchanged, so the kernel's
intrinsic default of `["all-apis", "offline_access"]` is applied.
`databricks-sql-python` is only registered for `sql` (+
`offline_access`) on the Databricks IdP, so an out-of-the-box
`Session(auth_type="oauth-u2m")` from Python fails the authorization
request:
```
access_denied — Scopes 'all-apis' are not assigned to the client
databricks-sql-python
```
- Fix: introduce `PYSQL_OAUTH_SCOPES = ["sql", "offline_access"]` next
to `PYSQL_OAUTH_CLIENT_ID` and default scopes to it when the caller
passed **neither** `client_id` nor `scopes`. Matches the Thrift
connector's `PYSQL_OAUTH_SCOPES` in `auth/auth.py`, restoring
`use_kernel=True` drop-in parity.
- A caller-supplied `client_id` still gets `scopes=None` forwarded
(custom clients may legitimately request `all-apis`). An explicit
`scopes` is always honoured verbatim.
## Test plan
- [x] Unit tests updated/added in `pyo3/src/auth.rs`:
- `u2m_defaults_client_id_and_scopes_to_python_connector` — both
defaults applied together.
- `u2m_explicit_client_id_overrides_default` — custom `client_id` keeps
`scopes=None` (kernel default wins).
- `u2m_explicit_scopes_are_honoured_verbatim` — caller-supplied scopes
pass through unchanged with the default client.
- [x] `cargo +stable fmt --all` + `cargo clippy --all-targets -- -D
warnings` clean.
- [x] `cargo test --lib --tests` — 14 passed, including all 9 auth
tests.
- [x] End-to-end against `e2-dogfood.staging.cloud.databricks.com`:
- **Before fix:** `sql.connect(auth_type="databricks-oauth",
use_kernel=True)` → `access_denied` from IdP.
- **After fix:** same call (no `oauth_scopes`) opens a session, browser
flow completes, `SELECT current_user()` returns the user.
This pull request and its description were written by Isaac.
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>1 parent 34b4c20 commit 136fd86
2 files changed
Lines changed: 107 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
79 | 103 | | |
80 | 104 | | |
81 | 105 | | |
| |||
157 | 181 | | |
158 | 182 | | |
159 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
160 | 213 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 214 | + | |
175 | 215 | | |
176 | | - | |
| 216 | + | |
177 | 217 | | |
178 | 218 | | |
179 | 219 | | |
| |||
285 | 325 | | |
286 | 326 | | |
287 | 327 | | |
288 | | - | |
| 328 | + | |
289 | 329 | | |
290 | 330 | | |
291 | 331 | | |
292 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
293 | 338 | | |
294 | 339 | | |
295 | 340 | | |
| |||
301 | 346 | | |
302 | 347 | | |
303 | 348 | | |
304 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
305 | 353 | | |
306 | 354 | | |
307 | 355 | | |
| |||
321 | 369 | | |
322 | 370 | | |
323 | 371 | | |
324 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
325 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
326 | 405 | | |
327 | 406 | | |
328 | 407 | | |
| |||
0 commit comments