Skip to content

Commit 5280f43

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

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
@@ -245,6 +245,7 @@ def get_new_connection(self, conn_params):
245245
options = conn_params.get('OPTIONS', {})
246246
driver = options.get('driver', 'ODBC Driver 13 for SQL Server')
247247
dsn = options.get('dsn', None)
248+
auth = options.get('Authentication', None)
248249

249250
# Microsoft driver names assumed here are:
250251
# * SQL Server Native Client 10.0/11.0
@@ -289,6 +290,16 @@ def get_new_connection(self, conn_params):
289290

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

293304
connstr = encode_connection_string(cstr_parts)
294305

0 commit comments

Comments
 (0)