Пример #1
0
        private async Task <MsalCacheHelperWrapper> GetProtectedCacheHelperAsync(bool async, string name)
        {
            StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder(name, Constants.DefaultMsalTokenCacheDirectory)
                                                          .WithMacKeyChain(Constants.DefaultMsalTokenCacheKeychainService, name)
                                                          .WithLinuxKeyring(Constants.DefaultMsalTokenCacheKeyringSchema, Constants.DefaultMsalTokenCacheKeyringCollection, name, Constants.DefaultMsaltokenCacheKeyringAttribute1, Constants.DefaultMsaltokenCacheKeyringAttribute2)
                                                          .Build();

            MsalCacheHelperWrapper cacheHelper = await InitializeCacheHelper(async, storageProperties).ConfigureAwait(false);

            return(cacheHelper);
        }
Пример #2
0
        private async Task <MsalCacheHelperWrapper> GetFallbackCacheHelperAsync(bool async, string name = Constants.DefaultMsalTokenCacheName)
        {
            StorageCreationProperties storageProperties = new StorageCreationPropertiesBuilder(name, Constants.DefaultMsalTokenCacheDirectory)
                                                          .WithMacKeyChain(Constants.DefaultMsalTokenCacheKeychainService, name)
                                                          .WithLinuxUnprotectedFile()
                                                          .Build();

            MsalCacheHelperWrapper cacheHelper = await InitializeCacheHelper(async, storageProperties).ConfigureAwait(false);

            return(cacheHelper);
        }
Пример #3
0
 internal TokenCache(TokenCachePersistenceOptions options, MsalCacheHelperWrapper cacheHelperWrapper, Func <IPublicClientApplication> publicApplicationFactory = null)
 {
     _cacheHelperWrapper             = cacheHelperWrapper ?? new MsalCacheHelperWrapper();
     _publicClientApplicationFactory = publicApplicationFactory ?? new Func <IPublicClientApplication>(() => PublicClientApplicationBuilder.Create(Guid.NewGuid().ToString()).Build());
     if (options is UnsafeTokenCacheOptions inMemoryOptions)
     {
         TokenCacheUpdatedAsync       = inMemoryOptions.TokenCacheUpdatedAsync;
         RefreshCacheFromOptionsAsync = inMemoryOptions.RefreshCacheAsync;
         _lastUpdated    = DateTimeOffset.UtcNow;
         _cacheAccessMap = new ConditionalWeakTable <object, CacheTimestamp>();
     }
     else
     {
         _allowUnencryptedStorage = options?.UnsafeAllowUnencryptedStorage ?? false;
         _name          = options?.Name ?? Constants.DefaultMsalTokenCacheName;
         _persistToDisk = true;
     }
 }
Пример #4
0
        internal virtual async Task RegisterCache(bool async, ITokenCache tokenCache, CancellationToken cancellationToken)
        {
            if (_persistToDisk)
            {
                MsalCacheHelperWrapper cacheHelper = await GetCacheHelperAsync(async, cancellationToken).ConfigureAwait(false);

                cacheHelper.RegisterCache(tokenCache);
            }
            else
            {
                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();
                }
            }
        }