Esempio n. 1
0
        /// <summary>
        /// Reads the cache data from the backend database.
        /// </summary>
        private void ReadCacheForSignedInUser()
        {
            if (_inMemoryCache == null) // first time access
            {
                _inMemoryCache = GetLatestUserRecordQuery().FirstOrDefault();
            }
            else
            {
                // retrieve last written record from the DB
                var lastwriteInDb = GetLatestUserRecordQuery().Select(n => n.LastWrite).FirstOrDefault();

                // if the persisted copy is newer than the in-memory copy
                if (lastwriteInDb > _inMemoryCache.LastWrite)
                {
                    // read from from storage, update in-memory copy
                    _inMemoryCache = GetLatestUserRecordQuery().FirstOrDefault();
                }
            }

            // Send data to the TokenCache instance
            _userTokenCache.DeserializeMsalV3((_inMemoryCache == null) ? null : _dataProtector.Unprotect(_inMemoryCache.CacheBits));
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the application's tokens from session cache.
        /// </summary>
        private void LoadAppTokenCacheFromSession()
        {
            _httpContext.Session.LoadAsync().Wait();

            s_sessionLock.EnterReadLock();
            try
            {
                byte[] blob;
                if (_httpContext.Session.TryGetValue(_appCacheId, out blob))
                {
                    Debug.WriteLine($"INFO: Deserializing session {_httpContext.Session.Id}, cacheId {_appCacheId}");
                    _apptokenCache.DeserializeMsalV3(blob);
                }
                else
                {
                    Debug.WriteLine($"INFO: cacheId {_appCacheId} not found in session {_httpContext.Session.Id}");
                }
            }
            finally
            {
                s_sessionLock.ExitReadLock();
            }
        }
        public void Load()
        {
            session.LoadAsync().Wait();

            SessionLock.EnterReadLock();
            try
            {
                byte[] blob;
                if (session.TryGetValue(CacheId, out blob))
                {
                    Debug.WriteLine($"INFO: Deserializing session {session.Id}, cacheId {CacheId}");
                    cache.DeserializeMsalV3(blob);
                }
                else
                {
                    Debug.WriteLine($"INFO: cacheId {CacheId} not found in session {session.Id}");
                }
            }
            finally
            {
                SessionLock.ExitReadLock();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Loads the application's token from memory cache.
 /// </summary>
 private void LoadAppTokenCacheFromMemory()
 {
     // Ideally, methods that load and persist should be thread safe. MemoryCache.Get() is thread safe.
     byte[] tokenCacheBytes = (byte[])memoryCache.Get(AppCacheId);
     AppTokenCache.DeserializeMsalV3(tokenCacheBytes);
 }
Esempio n. 5
0
 private void Load()
 {
     sessionLock.EnterReadLock();
     tokenCache.DeserializeMsalV3((byte[])httpContext.Session[cacheId]);
     sessionLock.ExitReadLock();
 }
Esempio n. 6
0
        private void Load(string key, ITokenCache tokenCache)
        {
            var data = (byte[])_cache.Get(key);

            tokenCache.DeserializeMsalV3(data);
        }