Ejemplo n.º 1
0
        /// <summary>Initializes a new instance of the <see cref="MsalPerUserMemoryTokenCacheProvider"/> class.</summary>
        /// <param name="cache">The memory cache instance</param>
        /// <param name="option"></param>
        public MsalPerUserMemoryTokenCacheProvider(IMemoryCache cache, MsalMemoryTokenCacheOptions option)
        {
            _memoryCache = cache;

            if (option != null)
            {
                _cacheOptions = new MsalMemoryTokenCacheOptions();
            }
            else
            {
                _cacheOptions = option;
            }
        }
Ejemplo n.º 2
0
        /// <summary>Adds the in-memory based per user token cache to the service collection.</summary>
        /// <param name="services">The services collection to add to.</param>
        /// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
        /// <returns></returns>
        public static IServiceCollection AddInMemoryPerUserTokenCache(
            this IServiceCollection services,
            MsalMemoryTokenCacheOptions cacheOptions)
        {
            services.AddMemoryCache();

            services.AddSingleton <IMsalUserTokenCacheProvider>(factory =>
            {
                var memoryCache = factory.GetRequiredService <IMemoryCache>();
                return(new MsalPerUserMemoryTokenCacheProvider(memoryCache, cacheOptions));
            });

            return(services);
        }
Ejemplo n.º 3
0
        /// <summary>Adds both the app and per-user in-memory token caches.</summary>
        /// <param name="services">The services collection to add to.</param>
        /// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
        /// <returns></returns>
        public static IServiceCollection AddInMemoryTokenCaches(
            this IServiceCollection services,
            MsalMemoryTokenCacheOptions cacheOptions = null)
        {
            var memoryCacheoptions = (cacheOptions == null)
                ? new MsalMemoryTokenCacheOptions
            {
                AbsoluteExpiration = DateTimeOffset.Now.AddDays(14)
            }
                : cacheOptions;

            AddInMemoryAppTokenCache(services, memoryCacheoptions);
            AddInMemoryPerUserTokenCache(services, memoryCacheoptions);
            return(services);
        }
Ejemplo n.º 4
0
        /// <summary>Adds the in-memory based application token cache to the service collection.</summary>
        /// <param name="services">The services collection to add to.</param>
        /// <param name="cacheOptions">the MSALMemoryTokenCacheOptions allows the caller to set the token cache expiration</param>
        public static IServiceCollection AddInMemoryAppTokenCache(
            this IServiceCollection services,
            MsalMemoryTokenCacheOptions cacheOptions)
        {
            services.AddMemoryCache();

            services.AddSingleton <IMsalAppTokenCacheProvider>(factory =>
            {
                var memoryCache    = factory.GetRequiredService <IMemoryCache>();
                var optionsMonitor = factory.GetRequiredService <IOptionsMonitor <AzureADOptions> >();

                return(new MsalAppMemoryTokenCacheProvider(memoryCache, cacheOptions, optionsMonitor));
            });

            return(services);
        }