Skip to content

Commit 8b94204

Browse files
author
Kalyan Krishna
authored
Merge pull request #70 from Azure-Samples/kkrishna/2-2
Added helper methods
2 parents 11229a5 + 5f27248 commit 8b94204

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

Microsoft.Identity.Web/Client/TokenCacheProviders/InMemory/MSALAppMemoryTokenCacheProviderExtension.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders
3232
{
3333
public static class MSALAppMemoryTokenCacheProviderExtension
3434
{
35+
/// <summary>Adds both the app and per-user in-memory token caches.</summary>
36+
/// <param name="services">The services collection to add to.</param>
37+
/// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
38+
/// <returns></returns>
3539
public static IServiceCollection AddInMemoryTokenCaches(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions = null)
3640
{
3741
var memoryCacheoptions = (cacheOptions == null) ? new MSALMemoryTokenCacheOptions { AbsoluteExpiration = DateTimeOffset.Now.AddDays(14) }
@@ -43,9 +47,9 @@ public static IServiceCollection AddInMemoryTokenCaches(this IServiceCollection
4347
}
4448

4549

46-
/// <summary>Adds the in memory based application token cache to the service collection.</summary>
50+
/// <summary>Adds the in-memory based application token cache to the service collection.</summary>
4751
/// <param name="services">The services collection to add to.</param>
48-
/// <param name="cacheOptions"></param>
52+
/// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
4953
public static IServiceCollection AddInMemoryAppTokenCache(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions)
5054
{
5155
services.AddMemoryCache();
@@ -61,8 +65,9 @@ public static IServiceCollection AddInMemoryAppTokenCache(this IServiceCollectio
6165
return services;
6266
}
6367

64-
/// <summary>Adds the in memory based per user token cache to the service collection.</summary>
68+
/// <summary>Adds the in-memory based per user token cache to the service collection.</summary>
6569
/// <param name="services">The services collection to add to.</param>
70+
/// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
6671
/// <returns></returns>
6772
public static IServiceCollection AddInMemoryPerUserTokenCache(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions)
6873
{

Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class MSALAppSessionTokenCacheProvider : IMSALAppTokenCacheProvider
6565
/// </summary>
6666
private string AppId;
6767

68+
/// <summary>Initializes a new instance of the <see cref="MSALAppSessionTokenCacheProvider"/> class.</summary>
69+
/// <param name="azureAdOptionsAccessor">The azure ad options accessor.</param>
70+
/// <exception cref="ArgumentNullException">AzureADOptions - The app token cache needs {nameof(AzureADOptions)}</exception>
6871
public MSALAppSessionTokenCacheProvider(IOptionsMonitor<AzureADOptions> azureAdOptionsAccessor)
6972
{
7073
if (azureAdOptionsAccessor.CurrentValue == null && string.IsNullOrWhiteSpace(azureAdOptionsAccessor.CurrentValue.ClientId))

Microsoft.Identity.Web/Client/TokenCacheProviders/Session/MSALAppSessionTokenCacheProviderExtension.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders
3030
{
3131
public static class MSALAppSessionTokenCacheProviderExtension
3232
{
33+
/// <summary>Adds both App and per-user session token caches.</summary>
34+
/// <param name="services">The services collection to add to.</param>
35+
/// <returns></returns>
36+
public static IServiceCollection AddSessionTokenCaches(this IServiceCollection services)
37+
{
38+
AddSessionAppTokenCache(services);
39+
AddSessionPerUserTokenCache(services);
40+
41+
return services;
42+
}
43+
3344
/// <summary>Adds the Http session based application token cache to the service collection.</summary>
3445
/// <param name="services">The services collection to add to.</param>
3546
/// <returns></returns>

Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ namespace Microsoft.Identity.Web.Client.TokenCacheProviders
3232
{
3333
public static class MSALAppSqlTokenCacheProviderExtension
3434
{
35-
/// <summary>
36-
/// Adds the Sql Server based application token cache to the service collection.
37-
/// </summary>
38-
/// <param name="services">The services collection to add to.</param>
35+
/// <summary>Adds the app and per user SQL token caches.</summary>
3936
/// <param name="configuration">The configuration instance from where this method pulls the connection string to the Sql database.</param>
37+
/// <param name="sqlTokenCacheOptions">The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string</param>
38+
/// <returns></returns>
39+
public static IServiceCollection AddSqlTokenCaches(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions)
40+
{
41+
AddSqlAppTokenCache(services, sqlTokenCacheOptions);
42+
AddSqlPerUserTokenCache(services, sqlTokenCacheOptions);
43+
return services;
44+
}
45+
46+
/// <summary>Adds the Sql Server based application token cache to the service collection.</summary>
47+
/// <param name="services">The services collection to add to.</param>
48+
/// <param name="sqlTokenCacheOptions">The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string</param>
4049
/// <returns></returns>
4150
public static IServiceCollection AddSqlAppTokenCache(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions)
4251
{
@@ -66,8 +75,8 @@ public static IServiceCollection AddSqlAppTokenCache(this IServiceCollection ser
6675
}
6776

6877
/// <summary>Adds the Sql Server based per user token cache to the service collection.</summary>
69-
/// <param name="services">The services.</param>
70-
/// <param name="configuration">The configuration instance from where this method pulls the connection string to the Sql database.</param>
78+
/// <param name="services">The services collection to add to.</param>
79+
/// <param name="sqlTokenCacheOptions">The MSALSqlTokenCacheOptions is used by the caller to specify the Sql connection string</param>
7180
/// <returns></returns>
7281
public static IServiceCollection AddSqlPerUserTokenCache(this IServiceCollection services, MSALSqlTokenCacheOptions sqlTokenCacheOptions)
7382
{

0 commit comments

Comments
 (0)