title: Connect to Azure SQL in Python with MFA Active Directory Interactive Authentication without using Microsoft.IdentityModel.Clients.ActiveDirectory dll
body: <p>To connect to Azure SQL Database using MFA (which is in SSMS as "Active Directory - Universal") Microsoft recommends and currently only has a tutorial on connecting with C# using Microsoft.IdentityModel.Clients.ActiveDirectory</p>
  
  <p>Setting <code>Authentication='Active Directory Interactive';</code> in a regular ODBC connection string from Python or Powershell results in the error</p>
  
  <pre><code>Cannot find an authentication provider for 'ActiveDirectoryInteractive'
  </code></pre>
  
  <p>This seems to be because per Microsoft's example code at <a href="https://docs.microsoft.com/en-us/azure/sql-database/active-directory-interactive-connect-azure-sql-db" rel="noreferrer">https://docs.microsoft.com/en-us/azure/sql-database/active-directory-interactive-connect-azure-sql-db</a> you need to explicitly create your own auth provider class when creating  the connection:</p>
  
  <pre><code>
          public static void Main(string[] args)
          {
              var provider = new ActiveDirectoryAuthProvider();
  
              SC.SqlAuthenticationProvider.SetProvider(
                  SC.SqlAuthenticationMethod.ActiveDirectoryInteractive,
                  //SC.SqlAuthenticationMethod.ActiveDirectoryIntegrated,  // Alternatives.
                  //SC.SqlAuthenticationMethod.ActiveDirectoryPassword,
                  provider);
  
              Program.Connection();
          }
  </code></pre>
  
  <p>I want to connect with pyodbc, so I can't implement the ActiveDirectoryInteractive provider.</p>
  
  <p>Is there any way to generically acquire a token using OAuth and use it in the connection string, or otherwise implement the ActiveDirectoryInteractive provider without using .NET? </p>