From a java web app in an azure app service, how do you query azure sql using the easy authed AD user

meyerovb 26 Reputation points
2023-03-22T13:43:28.2766667+00:00

I have an azure sql db with AD login enabled, and I created external users for my AD users. I can log into the azure sql using ssms via AD and it correctly shows me the AD username I logged in with when doing select SUSER_NAME(), whether it’s userA or userB.

I have an azure app service, java with tomcat, with easy auth set up (so it auths at the app service level, not the code level, and created the app registration for me).

From the java web app code of my app service, how do I query my azure sql as my easy authed AD user? So "select suser_name()" would return my easy authed ad user, whether it’s userA or userB.

Azure SQL Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,664 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 34,306 Reputation points Microsoft Employee
    2023-03-24T21:49:41.6933333+00:00

    Hi @meyerovb ,

    I'm glad that you were able to resolve your issue and thank you again for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution in case you'd like to "Accept" the answer.

    Issue:

    Using the Java web app code of your Azure app service, you were looking for a way to query Azure SQL as an Easy Auth Active Directory User.

    Solution:

    You Configured the App Service to return a usable access token and added the https://sql.azuresynapse-dogfood.net/user_impersonation instead of the Graph URL. Then you passed the x-ms-token-aad-access-token from the header to the SQLServerDataSource setAccessToken method as described in Tutorial: Authenticate and authorize users end-to-end in Azure App Service

    If you have any other questions or are running into more configuration issues, please let me know.

    Thank you again for your time and patience throughout this issue, and thank you for sharing your solution with the broader community!

    Please remember to "Accept the Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    0 comments No comments