简体   繁体   中英

ODBC connection to Azure using ActiveDirectoryInteractive

I am connecting to an Azure SQL database using pyodcb . We have multi-factor authentication enabled, so I am using ActiveDirectoryInteractive authentication. We also use single sign-on for Windows.

My code is as follows:

import pyodbc

driver = '{ODBC Driver 17 for SQL Server}'
server = 'xxxxxxxxxxxxx.database.windows.net'
database = 'xxxxxxxxxxxxx'
authentication = 'ActiveDirectoryInteractive'
username = 'xxxxxxxxxxxxx'
conn = pyodbc.connect(
    'DRIVER=' + driver + ';' +
    'SERVER=' + server + ';' +
    'DATABASE=' + database + ';' +
    'UID=' + username + ';' +
    'AUTHENTICATION=' + authentication + ';')
cursor = conn.cursor()

Running this script, I get the password prompt, followed by the prompt to enter my MFA code, and this connects successfully.

But I would have thought that these steps were unnecessary, given we're using single sign-on. In fact, if I close the password prompt without entering my password the connection is still made. So if single sign-on is working correctly and the password and MFA prompts are not necessary, how can I suppress them?

I'm not sure if this will disable it in Office 365, but if you want to disable MFA for users in Azure ad, I think the easiest way is to disable it directly in the portal.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM