Skip to content

Commit ce2ebae

Browse files
authored
Support custom oauth client id and redirect port (#75)
* Support custom oauth client id and rediret port range PySQL is used by other tools/CLIs which have own oauth client id, we need to expose oauth_client_id and oauth_redirect_port_range as the connection parameters to support this customization. Signed-off-by: Jacky Hu <[email protected]> * Change oauth redirect port range to port Signed-off-by: Jacky Hu <[email protected]> * Fix type check issue Signed-off-by: Jacky Hu <[email protected]> Signed-off-by: Jacky Hu <[email protected]>
1 parent 8674bae commit ce2ebae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/databricks/sql/auth/auth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ def get_python_sql_connector_auth_provider(hostname: str, **kwargs):
8989
use_cert_as_auth=kwargs.get("_use_cert_as_auth"),
9090
tls_client_cert_file=kwargs.get("_tls_client_cert_file"),
9191
oauth_scopes=PYSQL_OAUTH_SCOPES,
92-
oauth_client_id=PYSQL_OAUTH_CLIENT_ID,
93-
oauth_redirect_port_range=PYSQL_OAUTH_REDIRECT_PORT_RANGE,
92+
oauth_client_id=kwargs.get("oauth_client_id") or PYSQL_OAUTH_CLIENT_ID,
93+
oauth_redirect_port_range=[kwargs["oauth_redirect_port"]]
94+
if kwargs.get("oauth_client_id") and kwargs.get("oauth_redirect_port")
95+
else PYSQL_OAUTH_REDIRECT_PORT_RANGE,
9496
oauth_persistence=kwargs.get("experimental_oauth_persistence"),
9597
)
9698
return get_auth_provider(cfg)

src/databricks/sql/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def __init__(
6060
any IDP configured. This is only for interactive python applications and open a browser window.
6161
Note this is beta (private preview)
6262
63+
oauth_client_id: `str`, optional
64+
custom oauth client_id. If not specified, it will use the built-in client_id of databricks-sql-python.
65+
66+
oauth_redirect_port: `int`, optional
67+
port of the oauth redirect uri (localhost). This is required when custom oauth client_id
68+
`oauth_client_id` is set
69+
6370
experimental_oauth_persistence: configures preferred storage for persisting oauth tokens.
6471
This has to be a class implementing `OAuthPersistence`.
6572
When `auth_type` is set to `databricks-oauth` without persisting the oauth token in a persistence storage

0 commit comments

Comments
 (0)