Skip to content

Commit 5f7cfd2

Browse files
committed
Allow user to specify Authentication option and set correct connection string attributes for ActiveDirectoryInteractive authentication option
1 parent a738f41 commit 5f7cfd2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sql_server/pyodbc/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def get_new_connection(self, conn_params):
247247
options = conn_params.get('OPTIONS', {})
248248
driver = options.get('driver', 'ODBC Driver 13 for SQL Server')
249249
dsn = options.get('dsn', None)
250+
auth = options.get('Authentication', None)
250251

251252
# Microsoft driver names assumed here are:
252253
# * SQL Server Native Client 10.0/11.0
@@ -291,6 +292,16 @@ def get_new_connection(self, conn_params):
291292

292293
if ms_drivers.match(driver) and os.name == 'nt':
293294
cstr_parts['MARS_Connection'] = 'yes'
295+
296+
# User may want to use Azure AD Interactive connection option
297+
# It the user specified active directory interactive auth,
298+
# we neet to make sure pwd is not set and the connection is not
299+
# trusted as otherwise the driver will refuse to connect
300+
if auth:
301+
cstr_parts['Authentication'] = auth
302+
if auth == 'ActiveDirectoryInteractive':
303+
cstr_parts.pop('PWD')
304+
cstr_parts['Trusted_Connection'] = 'no'
294305

295306
connstr = encode_connection_string(cstr_parts)
296307

0 commit comments

Comments
 (0)