VS2019 Azure Service Authentication Account Selection for local debugging

Viewed 1292

Using VS2019, I have specified a temporary "developer account", using Tools/Options/Azure Service Authentication/Account Selection, for my app to "authenticate and access Azure resources with when debugging from Visual Studio". The developer account has access to an Azure SQL database. When I debug, my app gets a token as follows:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder["Data Source"] = serverName;
            builder["Initial Catalog"] = dbName;
            builder["Persist Security Info"] = "False";
            builder["MultipleActiveResultSets"] = "False";
            builder["Encrypt"] = "True";
            builder["TrustServerCertificate"] = "False";
            builder["Connect Timeout"] = 15;

            var cancellationToken = new CancellationToken();
            var conn = new SqlConnection(builder.ConnectionString);

            conn.AccessToken = new AzureServiceTokenProvider().GetAccessTokenAsync("https://database.windows.net/").GetAwaiter().GetResult();

            return conn.AccessToken;

However, when I examine the token returned it is NOT the token for the developer account identity I specified, it is for my normal identity I use to run Visual Studio. A co-worker has been able to do this in VS2019 with a developer account that's in the same Azure AD groups as my developer account. But for some local environment reason this is not working for me. Note that in SQL Server Management Studio I can access the SQL Azure database using my developer account with no problem at all.

Has anyone else had this debugging identity problem and been able to solve it? Thanks in advance for any light you can shed on this.

1 Answers

Sounds like you need to add the developer account to your Azure Service Authentication

enter image description here

On the drop down add the Dev account you are trying to use and make sure you make it your default account for Azure.

Related