Beispiel #1
0
        public static void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if the access operation resulted in a cache update
            if (args.HasStateChanged)
            {
                lock (s_fileLock)
                {
                    var cacheData = args.TokenCache.SerializeUnifiedAndAdalCache();

                    // reflect changes in the persistent store
                    if ((s_cacheStorage & CacheStorageType.Adal) == CacheStorageType.Adal)
                    {
                        if (!string.IsNullOrWhiteSpace(AdalV3CacheFileName))
                        {
                            CacheFileUtils.WriteToFileIfNotNull(AdalV3CacheFileName, cacheData.AdalV3State);
                        }
                    }

                    if ((s_cacheStorage & CacheStorageType.MsalV2) == CacheStorageType.MsalV2)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(UnifiedCacheFileName, cacheData.UnifiedState);
                    }
                }
            }
        }
        // Triggered right after ADAL accessed the cache.
        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if the access operation resulted in a cache update
            if (HasStateChanged)
            {
                lock (s_fileLock)
                {
                    // reflect changes in the persistent store
                    var cacheData = SerializeAdalAndUnifiedCache();

                    if ((_cacheStorageType & CacheStorageType.Adal) == CacheStorageType.Adal)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(AdalV3CacheFilePath, cacheData.AdalV3State);
                    }

                    if ((_cacheStorageType & CacheStorageType.MsalV2) == CacheStorageType.MsalV2)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(UnifiedCacheFilePath, cacheData.UnifiedState);
                    }

                    // once the write operation took place, restore the HasStateChanged bit to false
                    HasStateChanged = false;
                }
            }
        }
        public static void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if the access operation resulted in a cache update
            if (args.HasStateChanged)
            {
                lock (s_fileLock)
                {
                    var adalV3State = args.TokenCache.SerializeAdalV3();
#pragma warning disable CS0618 // Type or member is obsolete
                    var msalV2State = args.TokenCache.SerializeMsalV2();
#pragma warning restore CS0618 // Type or member is obsolete
                    var msalV3State = args.TokenCache.SerializeMsalV3();

                    // reflect changes in the persistent store
                    if ((s_cacheStorageType & CacheStorageType.Adal) == CacheStorageType.Adal)
                    {
                        if (!string.IsNullOrWhiteSpace(AdalV3CacheFileName))
                        {
                            CacheFileUtils.WriteToFileIfNotNull(AdalV3CacheFileName, adalV3State);
                        }
                    }

                    if ((s_cacheStorageType & CacheStorageType.MsalV2) == CacheStorageType.MsalV2)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(MsalV2CacheFileName, msalV2State);
                    }

                    if ((s_cacheStorageType & CacheStorageType.MsalV3) == CacheStorageType.MsalV3)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(MsalV3CacheFileName, msalV3State);
                    }
                }
            }
        }
Beispiel #4
0
        // Triggered right after ADAL accessed the cache.
        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if the access operation resulted in a cache update
            if (HasStateChanged)
            {
                lock (s_fileLock)
                {
                    var adalV3Bytes = SerializeAdalV3();
                    var msalV2Bytes = SerializeMsalV2();
                    var msalV3Bytes = SerializeMsalV3();

                    // reflect changes in the persistent store
                    if ((_cacheStorageType & CacheStorageType.Adal) == CacheStorageType.Adal)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(AdalV3CacheFilePath, adalV3Bytes);
                    }
                    if ((_cacheStorageType & CacheStorageType.MsalV2) == CacheStorageType.MsalV2)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(MsalV2CacheFilePath, msalV2Bytes);
                    }
                    if ((_cacheStorageType & CacheStorageType.MsalV3) == CacheStorageType.MsalV3)
                    {
                        CacheFileUtils.WriteToFileIfNotNull(MsalV3CacheFilePath, msalV3Bytes);
                    }

                    // once the write operation took place, restore the HasStateChanged bit to false
                    HasStateChanged = false;
                }
            }
        }
Beispiel #5
0
 // Triggered right after ADAL accessed the cache.
 private void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     // if the access operation resulted in a cache update
     if (HasStateChanged)
     {
         lock (s_fileLock)
         {
             // reflect changes in the persistent store
             CacheFileUtils.WriteToFileIfNotNull(CacheFilePath, Serialize());
             // once the write operation took place, restore the HasStateChanged bit to false
             HasStateChanged = false;
         }
     }
 }