databricks-sql-python icon indicating copy to clipboard operation
databricks-sql-python copied to clipboard

Support for Azure AD Service Principal with SQLAlchemy

Open FaresBadrCA opened this issue 2 years ago • 2 comments

Problem Summary:

When using Azure AD Service Principal, a client-id and client-secret are used to obtain a short-lived token. The token may be used in the connection string:

uri = f"databricks://token:{DATABRICKS_TOKEN}@{DATABRICKS_HOST}:443?http_path={DATABRICKS_HTTP_PATH}"
engine = create_engine(uri)

However, there is no mechanism to ensure that connections do not stay in the connection pool past the token expiration.

Proposed Solution:

Allow client_id and client_secret as connection arguments, and ensure connections do not stay open past token expiration.

url = f"databricks://{DATABRICKS_HOST}:443?http_path={DATABRICKS_HTTP_PATH}"    
engine = create_engine(url, connect_args = {client_id: CLIENT_ID, client_secret: CLIENT_SECRET, scopes: SCOPES  } )

FaresBadrCA avatar Oct 20 '23 05:10 FaresBadrCA

any updates on this ?

amirhessam88 avatar Jun 11 '24 23:06 amirhessam88