Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f5d474c
Add token introspection client for login.databricks.com discovery
simonfaltum Mar 10, 2026
f951fef
Fix discovery login tests to avoid hanging on PersistentAuth.Challenge
simonfaltum Mar 10, 2026
6b733d6
Improve discovery login: testability, scopes persistence, and error m…
simonfaltum Mar 11, 2026
fcf3ed5
Fix gofumpt and perfsprint lint issues
simonfaltum Mar 11, 2026
4cfbe37
Extract tip constant, reuse splitScopes in token.go, rename test
simonfaltum Mar 11, 2026
7a32dc1
Merge branch 'main' into simonfaltum/login-discovery
simonfaltum Mar 11, 2026
faafbb0
Remove account_id from discovery login profile save
simonfaltum Mar 12, 2026
3014886
Address review: validate flags in discovery mode, warn on account_id …
simonfaltum Mar 12, 2026
55fe3f5
Add tests for account_id mismatch warning in discovery login
simonfaltum Mar 12, 2026
3a392c7
Remove redundant introspection tests
simonfaltum Mar 12, 2026
b4b7147
Use env.Get(ctx, ...) instead of os.Getenv in discoveryLogin
simonfaltum Mar 12, 2026
85fa40c
Replace remaining os.Getenv with env.Get(ctx, ...) in login command
simonfaltum Mar 12, 2026
3f33cce
Validate discovered host is non-empty after discovery login
simonfaltum Mar 13, 2026
7d5624d
Reject --account-id, --workspace-id, --experimental-is-unified-host w…
simonfaltum Mar 13, 2026
c1e0fc4
Fix lint: use errors.New per perfsprint linter rule
simonfaltum Mar 13, 2026
5a21b82
Merge branch 'main' into simonfaltum/login-discovery
simonfaltum Mar 13, 2026
c6391af
Accept HTTP client parameter in IntrospectToken
simonfaltum Mar 16, 2026
28bbb68
Fix discovery login: HTTP client, scopes, stale fields, error messages
simonfaltum Mar 16, 2026
9b683f9
Use SDK config for introspection HTTP client TLS settings
simonfaltum Mar 16, 2026
67512b8
Simplify introspection HTTP client to clone DefaultTransport
simonfaltum Mar 16, 2026
5e91ce3
Merge branch 'main' into simonfaltum/login-discovery
simonfaltum Mar 20, 2026
186a91d
Add acceptance test for discovery login flow
simonfaltum Mar 22, 2026
fa4d62b
Address review: discoveryClient interface, consolidate flags, cleanup
simonfaltum Mar 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions acceptance/bin/discovery_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""
Simulates the login.databricks.com discovery flow for acceptance tests.

When the CLI opens this "browser" with the login.databricks.com URL,
the script extracts the OAuth parameters from the destination_url,
constructs a callback to localhost with an iss parameter pointing
at the testserver, and fetches it.

Usage: discovery_browser.py <url>
"""

import os
import sys
import urllib.parse
import urllib.request

if len(sys.argv) < 2:
sys.stderr.write("Usage: discovery_browser.py <url>\n")
sys.exit(1)

url = sys.argv[1]
parsed = urllib.parse.urlparse(url)
top_params = urllib.parse.parse_qs(parsed.query)

destination_url = top_params.get("destination_url", [None])[0]
if not destination_url:
sys.stderr.write(f"No destination_url found in: {url}\n")
sys.exit(1)

dest_parsed = urllib.parse.urlparse(destination_url)
dest_params = urllib.parse.parse_qs(dest_parsed.query)

redirect_uri = dest_params.get("redirect_uri", [None])[0]
state = dest_params.get("state", [None])[0]

if not redirect_uri or not state:
sys.stderr.write(f"Missing redirect_uri or state in destination_url: {destination_url}\n")
sys.exit(1)

# The testserver's host acts as the workspace issuer.
testserver_host = os.environ.get("DATABRICKS_HOST", "")
if not testserver_host:
sys.stderr.write("DATABRICKS_HOST not set\n")
sys.exit(1)

issuer = testserver_host.rstrip("/") + "/oidc"

# Build the callback URL with code, state, and iss (the workspace issuer).
callback_params = urllib.parse.urlencode(
{
"code": "oauth-code",
"state": state,
"iss": issuer,
}
)
callback_url = f"{redirect_uri}?{callback_params}"

try:
response = urllib.request.urlopen(callback_url)
if response.status != 200:
sys.stderr.write(f"Callback failed: {callback_url} (status {response.status})\n")
sys.exit(1)
except Exception as e:
sys.stderr.write(f"Callback failed: {callback_url} ({e})\n")
sys.exit(1)

sys.exit(0)
10 changes: 10 additions & 0 deletions acceptance/cmd/auth/login/discovery/out.databrickscfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
[DEFAULT]

[discovery-test]
host = [DATABRICKS_URL]
workspace_id = 12345
auth_type = databricks-cli

[__settings__]
default_profile = discovery-test
5 changes: 5 additions & 0 deletions acceptance/cmd/auth/login/discovery/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions acceptance/cmd/auth/login/discovery/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

>>> [CLI] auth login --profile discovery-test
Opening login.databricks.com in your browser...
Profile discovery-test was successfully saved

>>> [CLI] auth profiles
Name Host Valid
discovery-test (Default) [DATABRICKS_URL] YES

>>> print_requests.py --get //tokens/introspect
{
"method": "GET",
"path": "/api/2.0/tokens/introspect"
}
14 changes: 14 additions & 0 deletions acceptance/cmd/auth/login/discovery/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sethome "./home"

# Use the discovery browser script that simulates login.databricks.com
export BROWSER="discovery_browser.py"

trace $CLI auth login --profile discovery-test

trace $CLI auth profiles

# Verify the introspection endpoint was called (workspace_id in profile confirms this too).
trace print_requests.py --get //tokens/introspect

# Track the .databrickscfg file that was created to surface changes.
mv "./home/.databrickscfg" "./out.databrickscfg"
18 changes: 18 additions & 0 deletions acceptance/cmd/auth/login/discovery/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Ignore = [
"home"
]
RecordRequests = true

# Override the introspection endpoint so we can verify it gets called.
[[Server]]
Pattern = "GET /api/2.0/tokens/introspect"
Response.Body = '''
{
"principal_context": {
"authentication_scope": {
"account_id": "test-account-123",
"workspace_id": 12345
}
}
}
'''
Loading
Loading