本文整理汇总了C#中Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache类的典型用法代码示例。如果您正苦于以下问题:C# TokenCache类的具体用法?C# TokenCache怎么用?C# TokenCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenCache类属于Microsoft.IdentityModel.Clients.ActiveDirectory命名空间,在下文中一共展示了TokenCache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Authenticate
public IAccessToken Authenticate(
AzureAccount account,
AzureEnvironment environment,
string tenant,
SecureString password,
ShowDialog promptBehavior,
TokenCache tokenCache,
AzureEnvironment.Endpoint resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId)
{
var configuration = GetAdalConfiguration(environment, tenant, resourceId, tokenCache);
TracingAdapter.Information(Resources.AdalAuthConfigurationTrace, configuration.AdDomain, configuration.AdEndpoint,
configuration.ClientId, configuration.ClientRedirectUri, configuration.ResourceClientUri, configuration.ValidateAuthority);
IAccessToken token;
if (account.IsPropertySet(AzureAccount.Property.CertificateThumbprint))
{
var thumbprint = account.GetProperty(AzureAccount.Property.CertificateThumbprint);
token = TokenProvider.GetAccessTokenWithCertificate(configuration, account.Id, thumbprint, account.Type);
}
else
{
token = TokenProvider.GetAccessToken(configuration, promptBehavior, account.Id, password, account.Type);
}
account.Id = token.UserId;
return token;
}
开发者ID:rohmano,项目名称:azure-powershell,代码行数:28,代码来源:AuthenticationFactory.cs
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Redirect uri must match the redirect_uri used when requesting Authorization code.
string redirectUri = Properties.Settings.Default.RedirectUrl;
string authorityUri = "https://login.windows.net/common/oauth2/authorize/";
// Get the auth code
string code = Request.Params.GetValues(0)[0];
// Get auth token from auth code
TokenCache TC = new TokenCache();
AuthenticationContext AC = new AuthenticationContext(authorityUri, TC);
ClientCredential cc = new ClientCredential
(Properties.Settings.Default.ClientID,
Properties.Settings.Default.ClientSecretKey);
AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);
//Set Session "authResult" index string to the AuthenticationResult
Session["authResult"] = AR;
//Redirect back to Default.aspx
Response.Redirect("/Default.aspx");
}
开发者ID:ChrisMBenson,项目名称:PowerBI-CSharp,代码行数:26,代码来源:redirect.aspx.cs
示例3: AcquireTokenHandlerBase
protected AcquireTokenHandlerBase(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey, TokenSubjectType subjectType, bool callSync)
{
this.Authenticator = authenticator;
this.CallState = CreateCallState(this.Authenticator.CorrelationId, callSync);
Logger.Information(this.CallState,
string.Format("=== Token Acquisition started:\n\tAuthority: {0}\n\tResource: {1}\n\tClientId: {2}\n\tCacheType: {3}\n\tAuthentication Target: {4}\n\t",
authenticator.Authority, resource, clientKey.ClientId,
(tokenCache != null) ? tokenCache.GetType().FullName + string.Format(" ({0} items)", tokenCache.Count) : "null",
subjectType));
this.tokenCache = tokenCache;
if (string.IsNullOrWhiteSpace(resource))
{
var ex = new ArgumentNullException("resource");
Logger.Error(this.CallState, ex);
throw ex;
}
this.Resource = (resource != NullResource) ? resource : null;
this.ClientKey = clientKey;
this.TokenSubjectType = subjectType;
this.LoadFromCache = (tokenCache != null);
this.StoreToCache = (tokenCache != null);
this.SupportADFS = false;
}
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:27,代码来源:AcquireTokenHandlerBase.cs
示例4: AdalSilentTokenAcquisitionException
async Task IAuthenticationProvider.AuthenticateRequestAsync(HttpRequestMessage request)
{
// look in the IBotDataBag for the token
string objectIdentifier;
string tenantID = null;
byte[] tokenBlob = null;
bool found
= bag.TryGetValue(Keys.ObjectID, out objectIdentifier)
&& bag.TryGetValue(Keys.TenantID, out tenantID)
&& bag.TryGetValue(Keys.TokenCache, out tokenBlob);
// if not found, then throw the exception that will restart the login flow
if (! found)
{
throw new AdalSilentTokenAcquisitionException();
}
// deserialize the TokenCache and try to refresh the token silently
var tokenCache = new TokenCache(tokenBlob);
var token = await AcquireTokenSilentAsync(this.keys.ClientID, this.keys.ClientSecret, objectIdentifier, tenantID, tokenCache);
// update the IBotDataBag with the new token if it's changed
tokenBlob = tokenCache.Serialize();
bag.SetValue(Keys.TokenCache, tokenBlob);
// add the access token to the authentication header for the Microsoft Graph request
var accessToken = token.AccessToken;
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
}
开发者ID:CHENShuang1994,项目名称:BotBuilder,代码行数:29,代码来源:AuthenticationProvider.cs
示例5: EnsureAuthenticationContext
public async Task<bool> EnsureAuthenticationContext(string authority, bool show)
{
if (this.AuthenticationContext == null)
{
var cache = _cachePersist.Read();
if (cache != null)
{
var t = new TokenCache(cache);
this.AuthenticationContext = new AuthenticationContext(authority, t);
}
else
{
this.AuthenticationContext = new AuthenticationContext(authority);
}
}
var p = new PlatformParameters(show ? PromptBehavior.Always : PromptBehavior.Never, _deviceService.WindowHandle);
this.AuthenticationResult =
await this.AuthenticationContext.AcquireTokenAsync(
Office365ServicesUris.AADGraphAPIResourceId,
ClientId,
new Uri(RedirectUri),
p);
var tokenCache = AuthenticationContext.TokenCache.Serialize();
_cachePersist.Write(tokenCache);
return !string.IsNullOrWhiteSpace(this.AuthenticationResult.AccessToken);
}
开发者ID:jakkaj,项目名称:DayBar,代码行数:31,代码来源:AuthenticationHelper.cs
示例6: AcquireTokenSilentServiceErrorTestAsync
public async Task AcquireTokenSilentServiceErrorTestAsync()
{
Sts sts = new AadSts();
TokenCache cache = new TokenCache();
TokenCacheKey key = new TokenCacheKey(sts.Authority, sts.ValidResource, sts.ValidClientId, TokenSubjectType.User, "unique_id", "[email protected]");
cache.tokenCacheDictionary[key] = new AuthenticationResult("Bearer", "some-access-token",
"invalid-refresh-token", DateTimeOffset.UtcNow);
AuthenticationContext context = new AuthenticationContext(sts.Authority, sts.ValidateAuthority, cache);
try
{
await context.AcquireTokenSilentAsync(sts.ValidResource, sts.ValidClientId, new UserIdentifier("unique_id", UserIdentifierType.UniqueId));
Verify.Fail("AdalSilentTokenAcquisitionException was expected");
}
catch (AdalSilentTokenAcquisitionException ex)
{
Verify.AreEqual(AdalError.FailedToAcquireTokenSilently, ex.ErrorCode);
Verify.AreEqual(AdalErrorMessage.FailedToRefreshToken, ex.Message);
Verify.IsNotNull(ex.InnerException);
Verify.IsTrue(ex.InnerException is AdalException);
Verify.AreEqual(((AdalException)ex.InnerException).ErrorCode, "invalid_grant");
}
catch
{
Verify.Fail("AdalSilentTokenAcquisitionException was expected");
}
}
开发者ID:psignoret,项目名称:azure-activedirectory-library-for-dotnet,代码行数:29,代码来源:AcquireTokenSilentTests.cs
示例7: AcquireTokenHandlerBase
protected AcquireTokenHandlerBase(Authenticator authenticator, TokenCache tokenCache, string[] scope,
ClientKey clientKey, TokenSubjectType subjectType)
{
this.Authenticator = authenticator;
this.CallState = CreateCallState(this.Authenticator.CorrelationId);
PlatformPlugin.Logger.Information(this.CallState,
string.Format(
"=== accessToken Acquisition started:\n\tAuthority: {0}\n\tResource: {1}\n\tClientId: {2}\n\tCacheType: {3}\n\tAuthentication Target: {4}\n\t",
authenticator.Authority, scope, clientKey.ClientId,
(tokenCache != null)
? tokenCache.GetType().FullName + string.Format(" ({0} items)", tokenCache.Count)
: "null",
subjectType));
this.tokenCache = tokenCache;
this.ClientKey = clientKey;
this.TokenSubjectType = subjectType;
this.LoadFromCache = (tokenCache != null);
this.StoreToCache = (tokenCache != null);
this.SupportADFS = false;
if (ADALScopeHelper.IsNullOrEmpty(scope))
{
throw new ArgumentNullException("scope");
}
this.Scope = scope;
ValidateScopeInput(scope);
}
开发者ID:dstrockis,项目名称:aad-msa-channel9-demo,代码行数:29,代码来源:AcquireTokenHandlerBase.cs
示例8: TokenCache
static TokenCache()
{
DefaultShared = new TokenCache
{
BeforeAccess = PlatformPlugin.TokenCachePlugin.BeforeAccess,
AfterAccess = PlatformPlugin.TokenCachePlugin.AfterAccess
};
}
开发者ID:dstrockis,项目名称:aad-msa-channel9-demo,代码行数:8,代码来源:TokenCache.cs
示例9: AcquireTokenNonInteractiveHandler
public AcquireTokenNonInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string[] scope, string clientId, UserCredential userCredential)
: base(authenticator, tokenCache, scope, new ClientKey(clientId), TokenSubjectType.User)
{
if (userCredential == null)
{
throw new ArgumentNullException("userCredential");
}
this.userCredential = userCredential;
}
开发者ID:dstrockis,项目名称:aad-msa-channel9-demo,代码行数:10,代码来源:AcquireTokenNonInteractiveHandler.cs
示例10: UpdateTokenExpiryOnTokenCache
public static void UpdateTokenExpiryOnTokenCache(TokenCache cache, DateTimeOffset newExpiry)
{
var cacheDictionary = cache.tokenCacheDictionary;
var key = cacheDictionary.Keys.First();
cache.tokenCacheDictionary[key].ExpiresOn = newExpiry;
var value = cacheDictionary.Values.First();
cache.Clear();
cacheDictionary.Add(key, value);
}
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:10,代码来源:AdalFriend.cs
示例11: TokenCache
static TokenCache()
{
DefaultShared = new TokenCache();
#if !ADAL_NET
DefaultShared.BeforeAccess = DefaultTokenCache_BeforeAccess;
DefaultShared.AfterAccess = DefaultTokenCache_AfterAccess;
DefaultTokenCache_BeforeAccess(null);
#endif
}
开发者ID:MscrmTools,项目名称:MscrmTools.Xrm.Connection,代码行数:11,代码来源:TokenCache.cs
示例12: AuthenticationContextProxy
public AuthenticationContextProxy(string authority, bool validateAuthority, TokenCacheType tokenCacheType)
{
TokenCache tokenCache = null;
if (tokenCacheType == TokenCacheType.InMemory)
{
tokenCache = new TokenCache();
}
this.context = new AuthenticationContext(authority, validateAuthority, tokenCache);
this.context.CorrelationId = new Guid(FixedCorrelationId);
}
开发者ID:ankurchoubeymsft,项目名称:azure-activedirectory-library-for-dotnet,代码行数:11,代码来源:AuthenticationContextProxy.cs
示例13: AuthenticateAndAddToPowerBI
public void AuthenticateAndAddToPowerBI()
{
var tokenCache = new TokenCache();
var authenticationContext = new AuthenticationContext(AuthorityUri, tokenCache);
var result = authenticationContext.AcquireToken(ResourceUri, SelectedTenant.Client, new Uri(RedirectUri), PromptBehavior.RefreshSession);
var workspace = Workspace.GetFor(result.AccessToken);
var dataset = workspace.Datasets.GetByName(SelectedTenant.Dataset);
workspace.Rows.Add(dataset, new Message { ResponseInMinutes = Random.Next(0, 45) });
}
开发者ID:msdevno,项目名称:PowerBIDotNet,代码行数:11,代码来源:ViewModel.cs
示例14: EnsureAuthenticationContext
public void EnsureAuthenticationContext(TokenCache tokenCache)
{
if (ClaimsPrincipal.Current != null)
{
var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
var tenantId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
this.AuthenticationContext = new AuthenticationContext(
String.Format("{0}/{1}", AuthenticationHelper.AuthorizationUri, tenantId),
tokenCache);
}
}
开发者ID:CherifSy,项目名称:PnP,代码行数:13,代码来源:AuthenticationHelper.cs
示例15: AcquireTokenOnBehalfHandler
public AcquireTokenOnBehalfHandler(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey, UserAssertion userAssertion)
: base(authenticator, tokenCache, resource, clientKey, TokenSubjectType.UserPlusClient)
{
if (userAssertion == null)
{
throw new ArgumentNullException("userAssertion");
}
this.userAssertion = userAssertion;
this.DisplayableId = userAssertion.UserName;
this.SupportADFS = true;
}
开发者ID:varunpsr,项目名称:XamarinAzureAD,代码行数:13,代码来源:AcquireTokenOnBehalfHandler.cs
示例16: RefreshToken
public Tokens RefreshToken(Client client, Token refreshToken)
{
var tokenCache = new TokenCache();
var authenticationContext = new AuthenticationContext(AuthorityUri, tokenCache);
var result = authenticationContext.AcquireTokenByRefreshToken(refreshToken, client, ResourceUri);
var tokens = new Tokens
{
AccessToken = result.AccessToken,
RefreshToken = result.RefreshToken,
ExpiresOn = result.ExpiresOn
};
return tokens;
}
开发者ID:msdevno,项目名称:PowerBIDotNet,代码行数:13,代码来源:Authentication.cs
示例17: AzureSession
static AzureSession()
{
ClientFactory = new ClientFactory();
AuthenticationFactory = new AuthenticationFactory();
DataStore = new MemoryDataStore();
TokenCache = new TokenCache();
OldProfileFile = "WindowsAzureProfile.xml";
OldProfileFileBackup = "WindowsAzureProfile.xml.bak";
ProfileDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Resources.AzureDirectoryName); ;
ProfileFile = "AzureProfile.json";
TokenCacheFile = "TokenCache.dat";
}
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:14,代码来源:AzureSession.cs
示例18: AcquireTokenOnBehalfHandler
public AcquireTokenOnBehalfHandler(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey, UserAssertion userAssertion, bool callSync)
: base(authenticator, tokenCache, resource, clientKey, TokenSubjectType.UserPlusClient, callSync)
{
if (userAssertion == null)
{
throw new ArgumentNullException("userAssertion");
}
this.userAssertion = userAssertion;
this.DisplayableId = userAssertion.UserName;
this.assertionHash = PlatformSpecificHelper.CreateSha256Hash(userAssertion.Assertion);
this.SupportADFS = true;
}
开发者ID:MscrmTools,项目名称:MscrmTools.Xrm.Connection,代码行数:14,代码来源:AcquireTokenOnBehalfHandler.cs
示例19: AcquireTokenSilentHandler
public AcquireTokenSilentHandler(Authenticator authenticator, TokenCache tokenCache, string resource, ClientKey clientKey, UserIdentifier userId, bool callSync)
: base(authenticator, tokenCache, resource, clientKey, clientKey.HasCredential ? TokenSubjectType.UserPlusClient : TokenSubjectType.User, callSync)
{
if (userId == null)
{
throw new ArgumentNullException("userId", AdalErrorMessage.SpecifyAnyUser);
}
this.UniqueId = userId.UniqueId;
this.DisplayableId = userId.DisplayableId;
this.UserIdentifierType = userId.Type;
this.SupportADFS = true;
}
开发者ID:MscrmTools,项目名称:MscrmTools.Xrm.Connection,代码行数:14,代码来源:AcquireTokenSilentHandler.cs
示例20: AcquireTokenNonInteractiveHandler
public AcquireTokenNonInteractiveHandler(Authenticator authenticator, TokenCache tokenCache, string resource, string clientId, UserAssertion userAssertion)
: base(authenticator, tokenCache, resource, new ClientKey(clientId), TokenSubjectType.User)
{
if (userAssertion == null)
{
throw new ArgumentNullException("userAssertion");
}
if (string.IsNullOrWhiteSpace(userAssertion.AssertionType))
{
throw new ArgumentException(AdalErrorMessage.UserCredentialAssertionTypeEmpty, "userAssertion");
}
this.userAssertion = userAssertion;
}
开发者ID:SachiraChin,项目名称:azure-activedirectory-library-for-dotnet,代码行数:15,代码来源:AcquireTokenNonInteractiveHandler.cs
注:本文中的Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论