question

StevenBitaxi avatar image
0 Votes"
StevenBitaxi asked StevenBitaxi commented

Use DistributedSqlServerCache with an MSI in Azure SQL Db and remove credentials from Connection String

Good morning all, does anyone have an example implementation using MSI authentication for an Azure SQL Db used as a token cache?
I'm trying to get the credentials out of the connection string and use a token but there doesn't seem to be a place to pass it in:

         services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
             .EnableTokenAcquisitionToCallDownstreamApi(new[] { "https://database.windows.net//.default" })
             .AddDistributedTokenCaches();

         services.AddDistributedSqlServerCache(options =>
         {
             options.ConnectionString = 
                 Configuration.GetConnectionString("MyDbConnection");
             options.SchemaName = "dbo";
             options.TableName = "App_Token_Cache";
             options.DefaultSlidingExpiration = TimeSpan.FromMinutes(90);
         });

Do I need to create my own Cache service to accomplish this?

azure-sql-databaseazure-webapps-authentication
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

StevenBitaxi avatar image
0 Votes"
StevenBitaxi answered StevenBitaxi commented

Thank you very much Marilee. The AAD configuration and permissions are in place. A user of the 425Show forum advised me that I needed to use the correct connection string.

According to https://docs.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication?view=sql-server-ver15#using-active-directory-managed-identity-authentication the service will get the token. I don't need to handle it in the application.


 "Server=AZURESQLSERVER.database.windows.net,1433;Database=AZURE_DB;Authentication=Active Directory MSI;"
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@StevenBitaxi Can you confirm the issue is resolved for you?

0 Votes 0 ·

Yes, thank you. As per the answer I posted, this issue is solved.

0 Votes 0 ·