Skip to content

Commit e1d8c9a

Browse files
authored
Proposing a fix for #100 (#108)
This does not seem to make sense to have an absolute date to invaliidate the tokens, as when it's passed, no token can be added to the cache, Proposed to have a sliding duration.
1 parent 5563e2f commit e1d8c9a

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void AppTokenCacheAfterAccessNotification(TokenCacheNotificationArgs arg
128128
if (args.HasStateChanged)
129129
{
130130
// Reflect changes in the persistence store
131-
this.memoryCache.Set(this.AppCacheId, args.TokenCache.SerializeMsalV3(), CacheOptions.AbsoluteExpiration);
131+
this.memoryCache.Set(this.AppCacheId, args.TokenCache.SerializeMsalV3(), CacheOptions.SlidingExpiration);
132132
}
133133
}
134134
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static class MSALAppMemoryTokenCacheProviderExtension
3939
/// <returns></returns>
4040
public static IServiceCollection AddInMemoryTokenCaches(this IServiceCollection services, MSALMemoryTokenCacheOptions cacheOptions = null)
4141
{
42-
var memoryCacheoptions = (cacheOptions == null) ? new MSALMemoryTokenCacheOptions { AbsoluteExpiration = DateTimeOffset.Now.AddDays(14) }
42+
var memoryCacheoptions = (cacheOptions == null) ? new MSALMemoryTokenCacheOptions { SlidingExpiration = TimeSpan.FromDays(14) }
4343
: cacheOptions;
4444

4545
AddInMemoryAppTokenCache(services, memoryCacheoptions);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class MSALMemoryTokenCacheOptions
3838
/// <value>
3939
/// The AbsoluteExpiration value.
4040
/// </value>
41-
public DateTimeOffset AbsoluteExpiration
41+
public TimeSpan SlidingExpiration
4242
{
4343
get;
4444
set;
4545
}
4646

4747
public MSALMemoryTokenCacheOptions()
4848
{
49-
this.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
49+
this.SlidingExpiration = TimeSpan.FromHours(12);
5050
}
5151
}
5252
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private void UserTokenCacheAfterAccessNotification(TokenCacheNotificationArgs ar
104104
return;
105105

106106
// Ideally, methods that load and persist should be thread safe.MemoryCache.Get() is thread safe.
107-
this.memoryCache.Set(cacheKey, args.TokenCache.SerializeMsalV3(), this.CacheOptions.AbsoluteExpiration);
107+
this.memoryCache.Set(cacheKey, args.TokenCache.SerializeMsalV3(), this.CacheOptions.SlidingExpiration);
108108

109109
}
110110
}

0 commit comments

Comments
 (0)