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

Steven Bitaxi 1 Reputation point

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:

            .EnableTokenAcquisitionToCallDownstreamApi(new[] { "" })

        services.AddDistributedSqlServerCache(options =>
            options.ConnectionString = 
            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 Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,330 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Steven Bitaxi 1 Reputation point

    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 the service will get the token. I don't need to handle it in the application.

    ",1433;Database=AZURE_DB;Authentication=Active Directory MSI;"  

  2. Patel, Saurabh K 0 Reputation points

    Below code is not working with this connection string. Do I miss anything?? Connection string ",1433;Database=AZURE_DB;Authentication=Active Directory MSI;"

    services.AddDistributedSqlServerCache(options =>
                    options.ConnectionString = CRAFDBConnection;                
                    options.SchemaName = "dbo";
                    options.TableName = "SQLSessions";