Troubleshooting azure sql connection through token w/ sqlclient.
I'm trying to set up an inter-tenant connection from an azure hosted .NET application to an azure Sql database. Let's say the application is in tenant A, and the sql database in tenant B.
I would like to do this through token authorization, utilizing an enterprise application in tenant A with the application, that has a provisioned service principal in tenant B. In tenant B, I have given the service principal contributor and reader access to the sql server, as well as created a user in the database and given it reader and writer permissions. I've confirmed that the user exists and that its sid maps to the Application Id of the service principal. The sql server also has an Entra administrator assigned, and "allow azure services and resources to access the server" is set to true.
Yet when I try to connect by creating a sqlConnection object and assigning it an AccessToken, I receive and error saying Login failed for User ''. I've taken a look at the token utilized when generating the error, and the "aud" is "https://database.windows.net", the tenant id is that of tenant B with the sql server/database, the appid and oid correclty match to that of the service principal in tenant B, yet the connection still won't go through.
What else could I look into to troubleshoot this? Thanks.