public void DistributedCacheExtensionsTests() { CreateCca(); _confidentialApp.AddDistributedTokenCache(services => { services.AddDistributedMemoryCache(); }); Assert.NotNull(_confidentialApp.UserTokenCache); Assert.NotNull(_confidentialApp.AppTokenCache); }
public static IConfidentialClientApplication BuildConfidentialClientApplication() { if (clientapp == null) { clientapp = ConfidentialClientApplicationBuilder .Create(AuthenticationConfig.ClientId) .WithClientSecret(AuthenticationConfig.ClientSecret) .WithRedirectUri(AuthenticationConfig.RedirectUri) .WithAuthority(AadAuthorityAudience.AzureAdMultipleOrgs, false) .Build(); // After the ConfidentialClientApplication is created, we overwrite its default UserTokenCache serialization with our implementation // clientapp.AddInMemoryTokenCache(); clientapp.AddDistributedTokenCache(services => { services.AddDistributedMemoryCache(); services.Configure <MsalDistributedTokenCacheAdapterOptions>(o => { o.Encrypt = true; }); }); } return(clientapp); }
/// <summary> /// Shared method to create an IConfidentialClientApplication from configuration and attach the application's token cache implementation /// </summary> /// <param name="currentUser">The current ClaimsPrincipal</param> public static IConfidentialClientApplication BuildConfidentialClientApplication(ClaimsPrincipal currentUser) { IConfidentialClientApplication clientapp = ConfidentialClientApplicationBuilder.Create(Globals.ClientId) .WithClientSecret(Globals.ClientSecret) .WithRedirectUri(Globals.RedirectUri) .WithB2CAuthority(Globals.B2CAuthority) .Build(); clientapp.AddDistributedTokenCache(services => { services.AddDistributedMemoryCache(); services.Configure <MsalDistributedTokenCacheAdapterOptions>(o => { o.Encrypt = true; }); }); return(clientapp); }
public static IConfidentialClientApplication BuildConfidentialClientApplication() { if (clientapp == null) { clientapp = ConfidentialClientApplicationBuilder.Create(AuthenticationConfig.ClientId) .WithClientSecret(AuthenticationConfig.ClientSecret) .WithRedirectUri(AuthenticationConfig.RedirectUri) .WithAuthority(new Uri(AuthenticationConfig.Authority)) .Build(); clientapp.AddDistributedTokenCache(services => { // Do not use DistributedMemoryCache in production! // This is a memory cache which is not distributed and is not persisted. // It's useful for testing and samples, but in production use a durable distributed cache, // such as Redis. services.AddDistributedMemoryCache(); // The setting below shows encryption which works on a single machine. // In a distributed system, the encryption keys must be shared between all machines // For details see https://github.com/AzureAD/microsoft-identity-web/wiki/L1-Cache-in-Distributed-(L2)-Token-Cache#distributed-systems services.Configure <MsalDistributedTokenCacheAdapterOptions>(o => { o.Encrypt = true; }); }); /* * // Could also use other forms of cache, like Redis * // See https://aka.ms/ms-id-web/token-cache-serialization * clientapp.AddDistributedTokenCache(services => * { * services.AddStackExchangeRedisCache(options => * { * options.Configuration = "localhost"; * options.InstanceName = "SampleInstance"; * }); * }); */ } return(clientapp); }
public static IConfidentialClientApplication BuildConfidentialClientApplication(string clientId, string clientSecret, string redirectUri, string authority) { if (_cca == null) { _cca = ConfidentialClientApplicationBuilder.Create(clientId) .WithClientSecret(clientSecret) .WithRedirectUri(redirectUri) .WithAuthority(new Uri(authority)) .Build(); _cca.AddDistributedTokenCache(services => { services.AddDistributedMemoryCache(); services.Configure <MsalDistributedTokenCacheAdapterOptions>(o => { o.Encrypt = true; }); }); } return(_cca); }
public static IConfidentialClientApplication BuildConfidentialClientApplication() { if (clientapp == null) { clientapp = ConfidentialClientApplicationBuilder.Create(AuthenticationConfig.ClientId) .WithClientSecret(AuthenticationConfig.ClientSecret) .WithRedirectUri(AuthenticationConfig.RedirectUri) .WithAuthority(new Uri(AuthenticationConfig.Authority)) .Build(); // After the ConfidentialClientApplication is created, we overwrite its default UserTokenCache serialization with our implementation // clientapp.AddInMemoryTokenCache(); clientapp.AddDistributedTokenCache(services => { services.AddDistributedMemoryCache(); services.Configure <MsalDistributedTokenCacheAdapterOptions>(o => { o.Encrypt = true; }); }); /* * // Could also use other forms of cache, like Redis * // See https://aka.ms/ms-id-web/token-cache-serialization * clientapp.AddDistributedTokenCache(services => * { * services.AddStackExchangeRedisCache(options => * { * options.Configuration = "localhost"; * options.InstanceName = "SampleInstance"; * }); * }); */ } return(clientapp); }