Example #1
0
 // Notification raised after ADAL accessed the cache.
 // If the HasStateChanged flag is set, ADAL changed the content of the cache
 void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     if (this.HasStateChanged)
     {
         Cache = Cache ?? new UserTokenCach();
         Cache.webUserUniqueId = userId;
         Cache.cacheBits       = MachineKey.Protect(this.Serialize(), "ADALCache");
         Cache.LastWrite       = DateTime.Now;
         // update the DB and the lastwrite
         db.Entry(Cache).State = Cache.UserTokenCacheId == 0 ? EntityState.Added : EntityState.Modified;
         db.SaveChanges();
         this.HasStateChanged = false;
     }
 }