本文整理汇总了C#中Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCacheNotificationArgs类的典型用法代码示例。如果您正苦于以下问题:C# TokenCacheNotificationArgs类的具体用法?C# TokenCacheNotificationArgs怎么用?C# TokenCacheNotificationArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenCacheNotificationArgs类属于Microsoft.IdentityModel.Clients.ActiveDirectory命名空间,在下文中一共展示了TokenCacheNotificationArgs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: AfterAccessNotificationWithProperties
private void AfterAccessNotificationWithProperties(TokenCacheNotificationArgs args)
{
// if state changed
if (HasStateChanged)
{
var cachedTokens = Serialize();
var cachedTokensText = Convert.ToBase64String(cachedTokens);
_authProperties.Items[TokenCacheKey] = cachedTokensText;
}
}
开发者ID:CoryGM,项目名称:Security,代码行数:10,代码来源:AuthPropertiesTokenCache.cs
示例17: BeforeAccessNotification
/// <summary>
/// Triggered right before ADAL needs to access the cache.
/// Reload the cache from the persistent store in case it changed since the last access.
/// </summary>
/// <param name="args">Arguments for the TokenCacheNotification</param>
private void BeforeAccessNotification(TokenCacheNotificationArgs args)
{
lock (FileLock)
{
object cache = HttpContext.Current.Session[CacheId];
Deserialize(cache != null
? ProtectedData.Unprotect((byte[])cache, null, DataProtectionScope.LocalMachine)
: null);
}
}
开发者ID:dstrockis,项目名称:Katana-Sliding-Session,代码行数:15,代码来源:NaiveSessionCache.cs
示例18: 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)
{
var existingData = WindowsAzureProfile.Instance.ProfileStore.LoadTokenCache();
if (existingData != null)
{
this.Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
}
}
}
开发者ID:kangyangthu,项目名称:azure-sdk-tools,代码行数:13,代码来源:ProtectedFileTokenCache.cs
示例19: AfterAccessNotificationWithContext
private void AfterAccessNotificationWithContext(TokenCacheNotificationArgs args)
{
// if state changed
if (HasStateChanged)
{
AfterAccessNotificationWithProperties(args);
var cachedTokens = Serialize();
var cachedTokensText = Convert.ToBase64String(cachedTokens);
_authProperties.Items[TokenCacheKey] = cachedTokensText;
_httpContext.Authentication.SignInAsync(_signInScheme, _principal, _authProperties).Wait();
}
}
开发者ID:CoryGM,项目名称:Security,代码行数:13,代码来源:AuthPropertiesTokenCache.cs
示例20: AfterAccessNotification
private void AfterAccessNotification(TokenCacheNotificationArgs args)
{
if (this.HasStateChanged)
{
var state = this.Serialize();
var value = Convert.ToBase64String(state);
// This should cover enough time during which the tokens themselves should remain valid,
// since refresh tokens themselves are only valid for 14 days.
// See http://www.cloudidentity.com/blog/2015/03/20/azure-ad-token-lifetime/
var expirationTime = DateTime.UtcNow.AddDays(14);
var options = new CookieOptions { Expires = expirationTime, HttpOnly = true, Secure = true };
this.cookieManager.AppendResponseCookie(this.context, CookieName, value, options);
}
}
开发者ID:jelledruyts,项目名称:AzureResourceDashboard,代码行数:14,代码来源:CookieTokenCache.cs
注:本文中的Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCacheNotificationArgs类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论