Unable to login to Azure SQL database thru Azure App Service using User Managed Identity

mksharma 0 Reputation points Microsoft Employee
2023-11-25T05:56:05.4433333+00:00

I am trying to connect to an Azure SQL Database from an Azure App Service using User Managed Identity.

I have created a Managed Identity, granted it permissions to the database. I have also added the identity into the App-Service.

The code to connect to the database is as follows:

credential = identity.DefaultAzureCredential(exclude_interactive_browser_credential=False)
            
token = credential.get_token("https://database.windows.net/.default").token.encode("UTF-16-LE")
token_struct = struct.pack(f'
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,357 questions
{count} votes