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;
}
}