@@ -11,25 +11,22 @@ public class MSALSessionCache
1111 private static ReaderWriterLockSlim SessionLock = new ReaderWriterLockSlim ( LockRecursionPolicy . NoRecursion ) ;
1212 string UserId = string . Empty ;
1313 string CacheId = string . Empty ;
14- HttpContext httpContext = null ;
15-
16- ITokenCache cache ;
14+ private readonly HttpContext httpContext = null ;
15+ private ITokenCache cache ;
1716
1817 public MSALSessionCache ( string userId , HttpContext httpcontext )
1918 {
2019 // not object, we want the SUB
2120 UserId = userId ;
2221 CacheId = UserId + "_TokenCache" ;
2322 httpContext = httpcontext ;
24- Load ( ) ;
2523 }
2624
2725 public ITokenCache EnablePersistence ( ITokenCache cache )
2826 {
2927 this . cache = cache ;
3028 cache . SetBeforeAccess ( BeforeAccessNotification ) ;
3129 cache . SetAfterAccess ( AfterAccessNotification ) ;
32- Load ( ) ;
3330 return cache ;
3431 }
3532
@@ -47,31 +44,31 @@ public string ReadUserStateValue()
4744 SessionLock . ExitReadLock ( ) ;
4845 return state ;
4946 }
50- public void Load ( )
47+ public void Load ( TokenCacheNotificationArgs args )
5148 {
5249 SessionLock . EnterReadLock ( ) ;
5350 byte [ ] blob = httpContext . Session . Get ( CacheId ) ;
5451 if ( blob != null )
5552 {
56- cache . DeserializeMsalV3 ( blob ) ;
53+ args . TokenCache . DeserializeMsalV3 ( blob ) ;
5754 }
5855 SessionLock . ExitReadLock ( ) ;
5956 }
6057
61- public void Persist ( )
58+ public void Persist ( TokenCacheNotificationArgs args )
6259 {
6360 SessionLock . EnterWriteLock ( ) ;
6461
6562 // Reflect changes in the persistent store
66- httpContext . Session . Set ( CacheId , cache . SerializeMsalV3 ( ) ) ;
63+ httpContext . Session . Set ( CacheId , args . TokenCache . SerializeMsalV3 ( ) ) ;
6764 SessionLock . ExitWriteLock ( ) ;
6865 }
6966
7067 // Triggered right before MSAL needs to access the cache.
7168 // Reload the cache from the persistent store in case it changed since the last access.
7269 void BeforeAccessNotification ( TokenCacheNotificationArgs args )
7370 {
74- Load ( ) ;
71+ Load ( args ) ;
7572 }
7673
7774 // Triggered right after MSAL accessed the cache.
@@ -80,7 +77,7 @@ void AfterAccessNotification(TokenCacheNotificationArgs args)
8077 // if the access operation resulted in a cache update
8178 if ( args . HasStateChanged )
8279 {
83- Persist ( ) ;
80+ Persist ( args ) ;
8481 }
8582 }
8683 }
0 commit comments