public void Load(ITokenCacheSerializer tokenCacheSerializer)
        {
            TokenCacheLock.EnterReadLock();
            var sessionValue = _context.Session.Get(_sessionKey);

            if (sessionValue != null)
            {
                tokenCacheSerializer.DeserializeMsalV3(sessionValue);
            }

            TokenCacheLock.ExitReadLock();
        }
 public void Load(ITokenCacheSerializer cacheSerializer)
 {
     // Retrieve any existing tokens from session state.
     // Locks are used to ensure thread safety.
     SessionLock.EnterReadLock();
     byte[] blob = httpContext.Session.Get(CacheId);
     if (blob != null)
     {
         cacheSerializer.DeserializeMsalV3(blob);
     }
     SessionLock.ExitReadLock();
 }
Esempio n. 3
0
        private void Load(string key, ITokenCacheSerializer tokenCache)
        {
            using IServiceScope scope = serviceProvider.CreateScope();
            IMsalTokenDbContext ctx = scope.ServiceProvider.GetRequiredService <IMsalTokenDbContext>();

            MsalToken token = ctx.MsalTokens.Find(key);

            if (token != null)
            {
                tokenCache.DeserializeMsalV3(token.Value);
            }
        }
        /// <summary>
        /// Loads the user token cache from memory.
        /// </summary>
        private void LoadUserTokenCacheFromMemory(ITokenCacheSerializer tokenCache)
        {
            string cacheKey = this.GetMsalAccountId();

            if (string.IsNullOrWhiteSpace(cacheKey))
            {
                return;
            }

            // Ideally, methods that load and persist should be thread safe. MemoryCache.Get() is thread safe.
            byte[] tokenCacheBytes = (byte[])this.memoryCache.Get(this.GetMsalAccountId());
            tokenCache.DeserializeMsalV3(tokenCacheBytes);
        }
        /// <summary>
        /// Reads the cache data from the backend database.
        /// </summary>
        private void ReadCacheForSignedInApp(ITokenCacheSerializer tokenCache)
        {
            if (_inMemoryCache == null) // first time access
            {
                _inMemoryCache = GetLatestAppRecordQuery().FirstOrDefault();
            }
            else
            {
                // retrieve last written record from the DB
                var lastwriteInDb = GetLatestAppRecordQuery().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 = GetLatestAppRecordQuery().FirstOrDefault();
                }
            }

            // Send data to the TokenCache instance
            tokenCache.DeserializeMsalV3((_inMemoryCache == null) ? null : _dataProtector.Unprotect(_inMemoryCache.CacheBits));
        }
Esempio n. 6
0
        private void Load(string key, ITokenCacheSerializer tokenCache)
        {
            var data = (byte[])cache.Get(key);

            tokenCache.DeserializeMsalV3(data);
        }