本文整理汇总了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();
}
}
示例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;
}
}
示例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);
}
示例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
}
}
示例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");
}
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
}
示例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"));
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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);
}