當前位置: 首頁>>代碼示例>>C#>>正文


C# ActiveDirectory.TokenCacheNotificationArgs類代碼示例

本文整理匯總了C#中Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCacheNotificationArgs的典型用法代碼示例。如果您正苦於以下問題:C# TokenCacheNotificationArgs類的具體用法?C# TokenCacheNotificationArgs怎麽用?C# TokenCacheNotificationArgs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TokenCacheNotificationArgs類屬於Microsoft.IdentityModel.Clients.ActiveDirectory命名空間,在下文中一共展示了TokenCacheNotificationArgs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AfterAccessNotification

 /// <summary>
 /// Triggered right after ADAL accessed the cache.
 /// </summary>
 private void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     if (HasStateChanged)
     {
         Persist();
     }
 }
開發者ID:modulexcite,項目名稱:Research-Project-Code-Sample,代碼行數:10,代碼來源:SimpleTokenCache.cs

示例2: AfterAccessNotification

    // 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 state changed
        if (this.HasStateChanged)
        {
            //for a first time person, cache is null.
            if (Cache == null)
            {
                //created a new object
                Cache = new PerUserWebCache
                {
                    WebUserUniqueId = User,
                    CacheBits = this.Serialize(),
                    LastWrite = DateTime.Now
                };

                //add it to the DbContext
                db.PerUserCacheList.Add(Cache);
            }
            else
            {
                //update the CacheBits and LastWrite on the existing cache object.
                Cache.CacheBits = this.Serialize();
                Cache.LastWrite = DateTime.Now;
                db.Entry(Cache).State = EntityState.Modified;
            }

            //update the database
            db.SaveChanges();

            //reset the flag
            this.HasStateChanged = false;
        }
    }
開發者ID:nicofeijoo,項目名稱:azadaspnetmvcauth,代碼行數:35,代碼來源:EfAdalTokenCache.cs

示例3: BeforeAccessNotification

        // Notification raised before ADAL accesses the cache.
        // This is your chance to update the in-memory copy from the DB, if the in-memory version is stale
        void BeforeAccessNotification(TokenCacheNotificationArgs args)
        {
            if (Cache == null)
            {
                // first time access
                Cache = _Context.PerUserCacheList.FirstOrDefault(c => c.webUserUniqueId == User);
            }
            else
            {   // retrieve last write from the DB
                var status = from e in _Context.PerUserCacheList
                             where (e.webUserUniqueId == User)
                             select new
                             {
                                 LastWrite = e.LastWrite
                             };
                // if the in-memory copy is older than the persistent copy
                if (status.First().LastWrite > Cache.LastWrite)
                //// read from from storage, update in-memory copy 
                {
                    Cache = _Context.PerUserCacheList.FirstOrDefault(c => c.webUserUniqueId == User);
                }
            }


            this.Deserialize((Cache == null) ? null : Cache.cacheBits);
        }
開發者ID:TraianAlex,項目名稱:SP-AngularJS-ExpenseManager-Code-Sample,代碼行數:28,代碼來源:EFADALTokenCache.cs

示例4: BeforeAccess

        public void BeforeAccess(TokenCacheNotificationArgs args)
        {
            if (args.TokenCache.Count > 0)
            {
                // We assume that the cache has not changed since last write
                return;
            }

            try
            {
                SecStatusCode res;
                var rec = new SecRecord(SecKind.GenericPassword)
                {
                    Generic = NSData.FromString(LocalSettingsContainerName)
                };

                var match = SecKeyChain.QueryAsRecord(rec, out res);
                if (res == SecStatusCode.Success && match != null && match.ValueData != null)
                {
                    byte[] dataBytes = match.ValueData.ToArray();
                    if (dataBytes != null)
                    {
                        args.TokenCache.Deserialize(dataBytes);
                    }
                }
            }
            catch (Exception ex)
            {
                PlatformPlugin.Logger.Warning(null, "Failed to load cache: " + ex);
                // Ignore as the cache seems to be corrupt
            }
        }
開發者ID:varunpsr,項目名稱:XamarinAzureAD,代碼行數:32,代碼來源:TokenCachePlugin.cs

示例5: AfterAccessNotification

        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            lock (@lock)
            {
                if (File.Exists(_cacheFilePath) && this.HasStateChanged)
                {
                    Trace.WriteLine("VsoAdalTokenCache::AfterAccessNotification");

                    try
                    {
                        byte[] state = this.Serialize();

                        byte[] data = ProtectedData.Protect(state, null, DataProtectionScope.CurrentUser);

                        File.WriteAllBytes(_cacheFilePath, data);

                        this.HasStateChanged = false;
                    }
                    catch (Exception exception)
                    {
                        Trace.WriteLine(exception, "Error");
                    }
                }
            }
        }
開發者ID:dongruiqing,項目名稱:Git-Credential-Manager-for-Windows,代碼行數:25,代碼來源:VsoAdalTokenCache.cs

示例6: AfterAccess

        public void AfterAccess(TokenCacheNotificationArgs args)
        {
            if (args.TokenCache.HasStateChanged)
            {
                try
                {
                    var s = new SecRecord(SecKind.GenericPassword)
                    {
                        Generic = NSData.FromString(LocalSettingsContainerName)
                    };

                    var err = SecKeyChain.Remove(s);
                    if (args.TokenCache.Count > 0)
                    {
                        s.ValueData = NSData.FromArray(args.TokenCache.Serialize());
                        err = SecKeyChain.Add(s);
                    }

                    args.TokenCache.HasStateChanged = false;
                }
                catch (Exception ex)
                {
                    PlatformPlugin.Logger.Warning(null, "Failed to save cache: " + ex);
                }
            }
        }
開發者ID:varunpsr,項目名稱:XamarinAzureAD,代碼行數:26,代碼來源:TokenCachePlugin.cs

示例7: BeforeAccessNotification

 // Triggered right before ADAL needs to access the cache.
 // Reload the cache from the persistent store in case it changed since the last access.
 void BeforeAccessNotification(TokenCacheNotificationArgs args)
 {
     lock (FileLock)
     {
         this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), null, DataProtectionScope.CurrentUser) : null);
     }
 }
開發者ID:vibronet,項目名稱:GenderMixEstimator,代碼行數:9,代碼來源:FileCache.cs

示例8: AfterAccessNotification

        // 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 state changed
            if (this.HasStateChanged)
            {
                // check for an existing entry
                Cache = db.PerUserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == User);
                if (Cache == null)
                {
                    // if no existing entry for that user, create a new one
                    Cache = new PerUserTokenCache
                    {
                        webUserUniqueId = User,
                    };
                }

                // update the cache contents and the last write timestamp
                Cache.cacheBits = this.Serialize();
                Cache.LastWrite = DateTime.Now;

                // update the DB with modification or new entry
                db.Entry(Cache).State = Cache.Id == 0 ? EntityState.Added : EntityState.Modified;
                db.SaveChanges();
                this.HasStateChanged = false;
            }
        }
開發者ID:bstearns,項目名稱:VipSwapper,代碼行數:28,代碼來源:ADALTokenCache.cs

示例9: BeforeAccessNotification

        // Notification raised before ADAL accesses the cache.
        // This is your chance to update the in-memory copy from the DB, if the in-memory version is stale
        void BeforeAccessNotification(TokenCacheNotificationArgs args)
        {
            if (Cache == null)
            {
                // first time access
                Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);
            }
            else
            { 
                // retrieve last write from the DB
                var status = from e in db.UserTokenCacheList
                             where (e.webUserUniqueId == userId)
                select new
                {
                    LastWrite = e.LastWrite
                };

                // if the in-memory copy is older than the persistent copy
                if (status.First().LastWrite > Cache.LastWrite)
                {
                    // read from from storage, update in-memory copy
                    Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);
                }
            }
            this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits, "ADALCache"));
        }
開發者ID:modulexcite,項目名稱:TrainingContent,代碼行數:28,代碼來源:AdalTokenCache.cs

示例10: AfterAccessNotification

        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if state changed
            if (HasStateChanged)
            {
                // check for an existing entry
                _userAccount = _userAccountService.FetchByUsername(_userName);

                if (_userAccount == null)
                {
                    // Create the account
                    _userAccountService.Create(new CreateUserAccountModel()
                    {
                        Firstname = "",
                        Lastname = "",
                        Username = _userName,
                        CachedData = Serialize(),
                        UpdateDate = DateTime.Now
                    });
                }
                else
                {
                    // Update the account
                    _userAccount.CachedData = this.Serialize();
                    _userAccount.UpdateDate = DateTime.Now;

                    _userAccountService.UpdateCacheData(_userAccount);
                }

                HasStateChanged = false;
            }
        }
開發者ID:azure-appservice-samples,項目名稱:WingTipTickets,代碼行數:32,代碼來源:AdalTokenCache.cs

示例11: AfterAccessNotification

 /// <summary>
 /// Handles the AfterAccessNotification event, which is triggered right after ADAL accesses the cache.
 /// </summary>
 /// <param name="args">An instance of <see cref="Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCacheNotificationArgs"/> containing information for this event.</param>
 public void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     if (this.HasStateChanged)
     {
         try
         {
             if (this.Count > 0)
             {
                 _distributedCache.Set(_cacheKey, _protector.Protect(this.Serialize()));
                 _logger.TokensWrittenToStore(args.ClientId, args.UniqueId, args.Resource);
             }
             else
             {
                 // There are no tokens for this user/client, so remove them from the cache.
                 // This was previously handled in an overridden Clear() method, but the built-in Clear() calls this
                 // after the dictionary is cleared.
                 _distributedCache.Remove(_cacheKey);
                 _logger.TokenCacheCleared(_claimsPrincipal.GetObjectIdentifierValue(false) ?? "<none>");
             }
             this.HasStateChanged = false;
         }
         catch (Exception exp)
         {
             _logger.WriteToCacheFailed(exp);
             throw;
         }
     }
 }
開發者ID:Azure-Samples,項目名稱:guidance-identity-management-for-multitenant-apps,代碼行數:32,代碼來源:DistributedTokenCache.cs

示例12: AfterAccessNotification

 void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     if (this.HasStateChanged)
     {
         _items = this.Serialize();
         this.HasStateChanged = false;
     }
 }
開發者ID:farukc,項目名稱:Dash,代碼行數:8,代碼來源:DelegationToken.cs

示例13: AfterAccessNotification

 // Triggered right after ADAL accessed the cache.
 void AfterAccessNotification(TokenCacheNotificationArgs args)
 {
     // if the access operation resulted in a cache update
     if (this.HasStateChanged)
     {
         Persist();
     }
 }
開發者ID:Chen-Tang-2015,項目名稱:CalendarProtoType,代碼行數:9,代碼來源:NaiveSessionCache.cs

示例14: BeforeAccessNotification

 // Triggered right before ADAL needs to access the cache.
 // Reload the cache from the persistent store in case it changed since the last access.
 void BeforeAccessNotification(TokenCacheNotificationArgs args)
 {
     lock (FileLock)
     {
         this.Deserialize(File.Exists(CacheFilePath) ?
                              MachineKey.Unprotect(File.ReadAllBytes(CacheFilePath))
                              : null);
     }
 }
開發者ID:JonasSyrstad,項目名稱:Stardust,代碼行數:11,代碼來源:NativeTokenCache.cs

示例15: BeforeAccessNotificationWithContext

        private void BeforeAccessNotificationWithContext(TokenCacheNotificationArgs args)
        {
            // Retrieve the auth session with the cached tokens
             var authenticateContext = new AuthenticateContext(_signInScheme);
            _httpContext.Authentication.AuthenticateAsync(authenticateContext).Wait();
            _authProperties = new AuthenticationProperties(authenticateContext.Properties);
            _principal = authenticateContext.Principal;

            BeforeAccessNotificationWithProperties(args);
        }
開發者ID:CoryGM,項目名稱:Security,代碼行數:10,代碼來源:AuthPropertiesTokenCache.cs


注:本文中的Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCacheNotificationArgs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。