本文整理汇总了C#中System.Security.Claims.ClaimsPrincipal.GetIssuerValue方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsPrincipal.GetIssuerValue方法的具体用法?C# ClaimsPrincipal.GetIssuerValue怎么用?C# ClaimsPrincipal.GetIssuerValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Claims.ClaimsPrincipal
的用法示例。
在下文中一共展示了ClaimsPrincipal.GetIssuerValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAccessTokenForResourceAsync
private async Task<string> GetAccessTokenForResourceAsync(string resource, ClaimsPrincipal user)
{
var userId = user.GetObjectIdentifierValue();
var issuerValue = user.GetIssuerValue();
var userName = user.Identity?.Name;
try
{
_logger.BearerTokenAcquisitionStarted(resource, userName, issuerValue);
var authContext = await CreateAuthenticationContext(user)
.ConfigureAwait(false);
var result = await authContext.AcquireTokenSilentAsync(
resource,
await _credentialService.GetCredentialsAsync().ConfigureAwait(false),
new UserIdentifier(userId, UserIdentifierType.UniqueId))
.ConfigureAwait(false);
_logger.BearerTokenAcquisitionSucceeded(resource, userName, issuerValue);
return result.AccessToken;
}
catch (AdalException ex)
{
_logger.BearerTokenAcquisitionFailed(resource, userName, issuerValue, ex);
throw new AuthenticationException($"AcquireTokenSilentAsync failed for user: {userId}", ex);
}
}
开发者ID:Azure-Samples,项目名称:guidance-identity-management-for-multitenant-apps,代码行数:27,代码来源:SurveysTokenService.cs
示例2: RequestTokenAsync
/// <summary>
/// This method acquires an access token using an authorization code and ADAL. The access token is then cached
/// in a <see cref="TokenCache"/> to be used later (by calls to GetTokenForWebApiAsync).
/// </summary>
/// <param name="claimsPrincipal">A <see cref="ClaimsPrincipal"/> for the signed in user</param>
/// <param name="authorizationCode">a string authorization code obtained when the user signed in</param>
/// <param name="redirectUri">The Uri of the application requesting the access token</param>
/// <param name="resource">The resouce identifier of the target resource</param>
/// <returns>A <see cref="System.Threading.Tasks.Task{Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult}"/>.</returns>
public async Task<AuthenticationResult> RequestTokenAsync(
ClaimsPrincipal claimsPrincipal,
string authorizationCode,
string redirectUri,
string resource)
{
Guard.ArgumentNotNull(claimsPrincipal, nameof(claimsPrincipal));
Guard.ArgumentNotNullOrWhiteSpace(authorizationCode, nameof(authorizationCode));
Guard.ArgumentNotNullOrWhiteSpace(redirectUri, nameof(redirectUri));
Guard.ArgumentNotNullOrWhiteSpace(resource, nameof(resource));
try
{
var userId = claimsPrincipal.GetObjectIdentifierValue();
var issuerValue = claimsPrincipal.GetIssuerValue();
_logger.AuthenticationCodeRedemptionStarted(userId, issuerValue, resource);
var authenticationContext = await CreateAuthenticationContext(claimsPrincipal)
.ConfigureAwait(false);
var authenticationResult = await authenticationContext.AcquireTokenByAuthorizationCodeAsync(
authorizationCode,
new Uri(redirectUri),
await _credentialService.GetCredentialsAsync().ConfigureAwait(false),
resource)
.ConfigureAwait(false);
_logger.AuthenticationCodeRedemptionCompleted(userId, issuerValue, resource);
return authenticationResult;
}
catch (Exception ex)
{
_logger.AuthenticationCodeRedemptionFailed(ex);
throw;
}
}
开发者ID:Azure-Samples,项目名称:guidance-identity-management-for-multitenant-apps,代码行数:43,代码来源:SurveysTokenService.cs