

Follow these steps: Īfter you set this up, log in your Database from SSMS or other tool that you use to manage your database and execute those two statements: CREATE USER FROM EXTERNAL PROVIDERĮXEC sp_addrolemember 'db_owner', 'MyApp' Retrieving an AccessToken from Azure ADįirst things first, don't forget to install and import adal and pyodbc. New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId -DisplayName MyApp -Password SomeStrongPasswordįirst you need to set an AD Admin to your Azure SQL Logical Server. $app = Get-AzureRmADApplication -DisplayNameStartWith MyApp # PowerShell # get the application we want a service principal for


You can use this piece of code: # Azure CLI 2.0Īz ad sp create- for-rbac -name MyApp -password SomeStrongPassword To create one, you must first create an Application in your Azure AD.

Service Principals in Azure AD work just as SPN in an on-premises AD. To start I'm assuming you already have a SQL Database created in Azure, but if you don't click here to learn how to do it. Microsoft has created ADAL libraries in other languages as well and I'm using the Python one in this example ( ). Sounds like a bunch of work to port the whole code that does this authentication, so we might not see in a near future the Linux ODBC driver supporting Azure AD Federated users. The problem here is that my customer has federated their on-premises Active Directory (AD) with Azure AD through ADFS and this method of authentication is not yet supported in Linux as this is done through an ADAL DLL that is only available for Windows. Make sure you are using the latest version of the ODBC Driver (version 17). It also would be OK if they had their identities in Azure AD only, we could use simple Active Directory Password authentication and everything would work fine (Authentication=ActiveDirectoryPassword). This shouldn't be a problem if they could use SQL Authentication but Enterprises usually tend to user their Active Directory identities to have more control over access and so on. But I found no other easy way to describe what I could find out over the last week.Īll started with a customer trying to connect a Python application running in Linux to Azure SQL DB. Yes, I know, that's a long headline for an article.
