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

Issues with SSO using pyodbc #1403

Open
mattterry13 opened this issue Jan 29, 2025 · 0 comments
Open

Issues with SSO using pyodbc #1403

mattterry13 opened this issue Jan 29, 2025 · 0 comments

Comments

@mattterry13
Copy link

I'm having trouble using pyodbc to connect to a SQL database using Microsoft Entra MFA through my company. When I connect using SSMS, I select Database Engine as server type, select the appropriate server name, use Microsoft Entra MFA for Authentication type, first.last@company for username, and for Encryption selet Mandatory in the drop down. When I think click connect, it opens a browser window with the screen below asking me to pick an account (the one shown for my company is actuall [email protected]), and all I have to do is click on that account and the browser refreshes to show Authentication complete and I'm connected.

Image

I've treid various ways of connecting using pyodbc - using the below code I can get a windown to show up that is similar to the single sign-on window above, but rather than allowing me to click on account it asks me to input my password and then when I do, it asks if I want to receive an SMS or Call to authenticate that I need to answer, defeating the purpose of automating this connection.

Image

Here's the code used to get to that sign on screen in the second image:

server = 'sqlservername.database.windows.net' database = 'database_name' driver = '{ODBC Driver 18 for SQL Server}' conn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+ ';PORT=1433;DATABASE='+database+ ';Authentication=ActiveDirectoryInteractive;[email protected]')

I've also tried using the above code and setting UID=[email protected], but that doesn't work either. After reading through some articles I've tried multiple other authentication methods:

Authentication=ActiveDirectoryIntegrated - this results in an error saying failed to authenticate user (with both email formats)
Authentication=ActiveDirectoryPassword and pass along my pwrd - this gives an unknown error for both email formats
Authentication=ActiveDirectoryMsi - this give a requesting access token error.

Any assistance would be greatly apprecaited, if I could just get the python script to open the same authentication window in my browser I could use Selenium or something simliar to click on the correct account (or if this could be automated another way even better). Thanks in advance for any assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant