You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Today, token caches are still complex to use with MSAL.NET. There are several pieces of documentation to read
Describe the solution you'd like
We want to have one message, which is simple and the same for every case.
addition of token caches to MSAL.NET confidential client applications in ASP.NET, or .NET Core, or .NET FW. The app.UseInMemoryTokenCaches(); and app.UseTokenCaches could be added to Microsoft.Identity.Web (probably not MSAL.NET to avoid drawing a dependency on Microsoft.Extensions.Caching.Memory.
Note that
These methods should not be used in ASP.NET Core, where the token cache should still be added in the ConfigureService method of the Startup.cs.
I don't recommend providing higher level wrappers AddRedisTokenCaches etc ..., because this would mean Ms.Id.Web would need to depend on Microsoft.Extensions.Caching.StackExchangeRedis etc ..
Proposed experience
// (Simulates the configuration, could be a IConfiguration or anything)Dictionary<string,string>Configuration=newDictionary<string,string>();// Create the confidential client applicationIConfidentialClientApplicationapp;app=ConfidentialClientApplicationBuilder.Create(clientId)// Alternatively to the certificate you can use .WithClientSecret(clientSecret).WithCertificate(certDescription.Certificate).WithTenantId(tenant).Build();// In memory token cacheapp.UseInMemoryTokenCaches();// Or// In memory distributed token cacheapp.UseDistributedTokenCaches(services =>{// In net472, requires to reference Microsoft.Extensions.Caching.Memoryservices.AddDistributedMemoryCache();});// Or// SQL Server token cacheapp.UseDistributedTokenCaches(services =>{services.AddDistributedSqlServerCache(options =>{// In net472, requires to reference Microsoft.Extensions.Caching.Memory// Requires to reference Microsoft.Extensions.Caching.SqlServeroptions.ConnectionString=@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TestCache;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";options.SchemaName="dbo";options.TableName="TestCache";// You don't want the SQL token cache to be purged before the access token has expired. Usually// access tokens expire after 1 hour (but this can be changed by token lifetime policies), whereas// the default sliding expiration for the distributed SQL database is 20 mins. // Use a value which is above 60 mins (or the lifetime of a token in case of longer lived tokens)options.DefaultSlidingExpiration=TimeSpan.FromMinutes(90);});});// Or // Redis token cacheapp.UseDistributedTokenCaches(services =>{// Requires to reference Microsoft.Extensions.Caching.StackExchangeRedisservices.AddStackExchangeRedisCache(options =>{options.Configuration="localhost";options.InstanceName="Redis";});});// Or// Cosmos DB token cacheapp.UseDistributedTokenCaches(services =>{// Requires to reference Microsoft.Extensions.Caching.Cosmos (preview)services.AddCosmosCache((CosmosCacheOptionscacheOptions)=>{cacheOptions.ContainerName=Configuration["CosmosCacheContainer"];cacheOptions.DatabaseName=Configuration["CosmosCacheDatabase"];cacheOptions.ClientBuilder=newCosmosClientBuilder(Configuration["CosmosConnectionString"]);cacheOptions.CreateIfNotExists=true;});});
Describe alternatives you've considered
Add these to MSAL.NET directly, but this would draw un-desired dependencies as MSAL.NET needs to say small for some scenarios.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Today, token caches are still complex to use with MSAL.NET. There are several pieces of documentation to read
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Multi-tenant-client_credential-use for the multi-tenant options
Describe the solution you'd like
We want to have one message, which is simple and the same for every case.
addition of token caches to MSAL.NET confidential client applications in ASP.NET, or .NET Core, or .NET FW. The
app.UseInMemoryTokenCaches();
andapp.UseTokenCaches
could be added to Microsoft.Identity.Web (probably not MSAL.NET to avoid drawing a dependency on Microsoft.Extensions.Caching.Memory.Note that
These methods should not be used in ASP.NET Core, where the token cache should still be added in the
ConfigureService
method of theStartup.cs
.I don't recommend providing higher level wrappers AddRedisTokenCaches etc ..., because this would mean Ms.Id.Web would need to depend on Microsoft.Extensions.Caching.StackExchangeRedis etc ..
Proposed experience
Describe alternatives you've considered
Add these to MSAL.NET directly, but this would draw un-desired dependencies as MSAL.NET needs to say small for some scenarios.
The text was updated successfully, but these errors were encountered: