Exemplo n.º 1
0
        internal virtual async Task RegisterCache(bool async, ITokenCache tokenCache, CancellationToken cancellationToken)
        {
            if (async)
            {
                await _lock.WaitAsync(cancellationToken).ConfigureAwait(false);
            }
            else
            {
                _lock.Wait(cancellationToken);
            }

            try
            {
                if (!_cacheAccessMap.TryGetValue(tokenCache, out _))
                {
                    tokenCache.SetBeforeAccessAsync(OnBeforeCacheAccessAsync);

                    tokenCache.SetAfterAccessAsync(OnAfterCacheAccessAsync);

                    _cacheAccessMap.Add(tokenCache, new CacheTimestamp());
                }
            }
            finally
            {
                _lock.Release();
            }
        }
 /// <summary>
 /// Create token cache
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="tokenCache"></param>
 /// <param name="cacheKey"></param>
 public MsalTokenCacheDecorator(ICache cache, ITokenCache tokenCache, string cacheKey)
 {
     _cache    = cache;
     _cacheKey = cacheKey;
     tokenCache.SetBeforeAccessAsync(OnBeforeAccessAsync);
     tokenCache.SetAfterAccessAsync(OnAfterAccessAsync);
 }
Exemplo n.º 3
0
 public void EnablePersistence(ITokenCache cache)
 {
     this.cache = cache;
     cache.SetBeforeAccessAsync(BeforeAccessNotificationAsync);
     cache.SetAfterAccessAsync(AfterAccessNotificationAsync);
     cache.SetBeforeWriteAsync(BeforeAccessNotificationAsync);
 }
        /// <summary>
        /// Initializes the token cache serialization.
        /// </summary>
        /// <param name="tokenCache">Token cache to serialize/deserialize</param>
        /// <returns></returns>
        public Task InitializeAsync(ITokenCache tokenCache)
        {
            tokenCache.SetBeforeAccessAsync(OnBeforeAccessAsync);
            tokenCache.SetAfterAccessAsync(OnAfterAccessAsync);
            tokenCache.SetBeforeWriteAsync(OnBeforeWriteAsync);

            return(Task.CompletedTask);
        }
        /// <summary>Initializes this instance of TokenCacheProvider with essentials to initialize themselves.</summary>
        /// <param name="tokenCache">The token cache instance of MSAL application.</param>
        /// <param name="httpcontext">The Httpcontext whose Session will be used for caching.This is required by some providers.</param>
        public void Initialize(ITokenCache tokenCache, HttpContext httpcontext)
        {
            this.AppCacheId = this.appId + "_AppTokenCache";

            tokenCache.SetBeforeAccessAsync(this.AppTokenCacheBeforeAccessNotificationAsync);
            tokenCache.SetAfterAccessAsync(this.AppTokenCacheAfterAccessNotificationAsync);
            tokenCache.SetBeforeWrite(this.AppTokenCacheBeforeWriteNotification);
        }
Exemplo n.º 6
0
 public static void Initialize(string key, IDistributedCache distributedCache, ITokenCache tokenCache)
 {
     _key        = key;
     _cache      = distributedCache;
     _tokenCache = tokenCache;
     _tokenCache.SetBeforeAccessAsync(OnBeforeAccessHandler);
     _tokenCache.SetAfterAccessAsync(OnAfterAccessHandler);
 }
        /// <summary>
        /// Initializes the token cache serialization.
        /// </summary>
        /// <param name="tokenCache">Token cache to serialize/deserialize.</param>
        public void Initialize(ITokenCache tokenCache)
        {
            if (tokenCache == null)
            {
                throw new ArgumentNullException(nameof(tokenCache));
            }

            tokenCache.SetBeforeAccessAsync(OnBeforeAccessAsync);
            tokenCache.SetAfterAccessAsync(OnAfterAccessAsync);
            tokenCache.SetBeforeWriteAsync(OnBeforeWriteAsync);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes the token cache serialization.
        /// </summary>
        /// <param name="tokenCache">Token cache to serialize/deserialize</param>
        /// <returns></returns>
        public Task InitializeAsync(ITokenCache tokenCache)
        {
            if (tokenCache == null)
            {
                throw new ArgumentNullException(nameof(tokenCache));
            }
            tokenCache.SetBeforeAccessAsync(OnBeforeAccessAsync);
            tokenCache.SetAfterAccessAsync(OnAfterAccessAsync);
            tokenCache.SetBeforeWriteAsync(OnBeforeWriteAsync);

            return(Task.CompletedTask);
        }
        /// <summary>Initializes the cache instance</summary>
        /// <param name="tokenCache">The ITokenCache passed through the constructor</param>
        /// <param name="user">The signed-in user for whom the cache needs to be established..</param>
        public Task InitializeAsync(ITokenCache tokenCache, ClaimsPrincipal user)
        {
            SignedInUser = user;

            if (tokenCache == null)
            {
                throw new ArgumentNullException(nameof(tokenCache));
            }

            tokenCache.SetBeforeAccessAsync(OnBeforeAccessAsync);
            tokenCache.SetAfterAccessAsync(OnAfterAccessAsync);

            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
 public void Bind(ITokenCache tokenCache)
 {
     tokenCache.SetBeforeAccessAsync(BeforeAccessNotificationAsync);
     tokenCache.SetAfterAccessAsync(AfterAccessNotificationAsync);
 }
Exemplo n.º 11
0
 public static void Initialize(ITokenCache tokenCache)
 {
     tokenCache.SetBeforeAccessAsync(BeforeAccessAsync);
     tokenCache.SetAfterAccessAsync(AfterAccessAsync);
 }