Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ad auth #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions sql_server/pyodbc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def get_new_connection(self, conn_params):
options = conn_params.get('OPTIONS', {})
driver = options.get('driver', 'ODBC Driver 13 for SQL Server')
dsn = options.get('dsn', None)
auth = options.get('Authentication', None)

# Microsoft driver names assumed here are:
# * SQL Server Native Client 10.0/11.0
Expand Down Expand Up @@ -292,6 +293,17 @@ def get_new_connection(self, conn_params):
if ms_drivers.match(driver) and os.name == 'nt':
cstr_parts['MARS_Connection'] = 'yes'

# User may want to use Azure AD Interactive connection option
# It the user specified active directory interactive auth,
# we neet to make sure pwd is not set and the connection is not
# trusted as otherwise the driver will refuse to connect
if auth:
cstr_parts['Authentication'] = auth
if auth == 'ActiveDirectoryInteractive':
cstr_parts.setdefault('UID', '')
cstr_parts.pop('PWD', '')
cstr_parts['Trusted_Connection'] = 'no'

connstr = encode_connection_string(cstr_parts)

# extra_params are glued on the end of the string without encoding,
Expand Down