From 5f27248e12a8643b5f79a8c4c81f1eabe3d0a9e9 Mon Sep 17 00:00:00 2001 From: Kalyan Krishna Date: Mon, 25 Mar 2019 19:01:10 -0700 Subject: [PATCH] Added helper methods --- ...SALAppMemoryTokenCacheProviderExtension.cs | 11 +++++++--- .../MSALAppSessionTokenCacheProvider.cs | 3 +++ ...ALAppSessionTokenCacheProviderExtension.cs | 11 ++++++++++ .../MSALAppSqlTokenCacheProviderExtension.cs | 21 +++++++++++++------ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Microsoft.Identity.Web/Client/TokenCacheProviders/InMemory/MSALAppMemoryTokenCacheProviderExtension.cs b/Microsoft.Identity.Web/Client/TokenCacheProviders/InMemory/MSALAppMemoryTokenCacheProviderExtension.cs index 916154fd..f8affca9 100644 --- a/Microsoft.Identity.Web/Client/TokenCacheProviders/InMemory/MSALAppMemoryTokenCacheProviderExtension.cs +++ b/Microsoft.Identity.Web/Client/TokenCacheProviders/InMemory/MSALAppMemoryTokenCacheProviderExtension.cs @@ -32,6 +32,10 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders { public static class MSALAppMemoryTokenCacheProviderExtension { + /// Adds both the app and per-user in-memory token caches. + /// The services collection to add to. + /// the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration + /// public static IServiceCollection AddInMemoryTokenCaches(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions = null) { var memoryCacheoptions = (cacheOptions == null) ? new MSALMemoryTokenCacheOptions { AbsoluteExpiration = DateTimeOffset.Now.AddDays(14) } @@ -43,9 +47,9 @@ public static IServiceCollection AddInMemoryTokenCaches(this IServiceCollection } - /// Adds the in memory based application token cache to the service collection. + /// Adds the in-memory based application token cache to the service collection. /// The services collection to add to. - /// + /// the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration public static IServiceCollection AddInMemoryAppTokenCache(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions) { services.AddMemoryCache(); @@ -61,8 +65,9 @@ public static IServiceCollection AddInMemoryAppTokenCache(this IServiceCollectio return services; } - /// Adds the in memory based per user token cache to the service collection. + /// Adds the in-memory based per user token cache to the service collection. /// The services collection to add to. + /// the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration /// public static IServiceCollection AddInMemoryPerUserTokenCache(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions) { diff --git a/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProvider.cs b/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProvider.cs index e58abc07..51bb8cc1 100644 --- a/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProvider.cs +++ b/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProvider.cs @@ -65,6 +65,9 @@ public class MSALAppSessionTokenCacheProvider : IMSALAppTokenCacheProvider /// private string AppId; + /// Initializes a new instance of the class. + /// The azure ad options accessor. + /// AzureADOptions - The app token cache needs {nameof(AzureADOptions)} public MSALAppSessionTokenCacheProvider(IOptionsMonitor azureAdOptionsAccessor) { if (azureAdOptionsAccessor.CurrentValue == null && string.IsNullOrWhiteSpace(azureAdOptionsAccessor.CurrentValue.ClientId)) diff --git a/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProviderExtension.cs b/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProviderExtension.cs index e1d7b88c..58d75bf6 100644 --- a/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProviderExtension.cs +++ b/Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProviderExtension.cs @@ -30,6 +30,17 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders { public static class MSALAppSessionTokenCacheProviderExtension { + /// Adds both App and per-user session token caches. + /// The services collection to add to. + /// + public static IServiceCollection AddSessionTokenCaches(this IServiceCollection services) + { + AddSessionAppTokenCache(services); + AddSessionPerUserTokenCache(services); + + return services; + } + /// Adds the Http session based application token cache to the service collection. /// The services collection to add to. /// diff --git a/Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs b/Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs index ccfac92d..94638130 100644 --- a/Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs +++ b/Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs @@ -32,11 +32,20 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders { public static class MSALAppSqlTokenCacheProviderExtension { - /// - /// Adds the Sql Server based application token cache to the service collection. - /// - /// The services collection to add to. + /// Adds the app and per user SQL token caches. /// The configuration instance from where this method pulls the connection string to the Sql database. + /// The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string + /// + public static IServiceCollection AddSqlTokenCaches(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions) + { + AddSqlAppTokenCache(services, sqlTokenCacheOptions); + AddSqlPerUserTokenCache(services, sqlTokenCacheOptions); + return services; + } + + /// Adds the Sql Server based application token cache to the service collection. + /// The services collection to add to. + /// The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string /// public static IServiceCollection AddSqlAppTokenCache(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions) { @@ -66,8 +75,8 @@ public static IServiceCollection AddSqlAppTokenCache(this IServiceCollection ser } /// Adds the Sql Server based per user token cache to the service collection. - /// The services. - /// The configuration instance from where this method pulls the connection string to the Sql database. + /// The services collection to add to. + /// The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string /// public static IServiceCollection AddSqlPerUserTokenCache(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions) {