Tailspin.Surveys.Web.Security.SurveysTokenService.RequestTokenAsync C# (CSharp) Method

RequestTokenAsync() public method

This method acquires an access token using an authorization code and ADAL. The access token is then cached in a TokenCache to be used later (by calls to GetTokenForWebApiAsync).
public RequestTokenAsync ( ClaimsPrincipal claimsPrincipal, string authorizationCode, string redirectUri, string resource ) : Task
claimsPrincipal System.Security.Claims.ClaimsPrincipal A for the signed in user
authorizationCode string a string authorization code obtained when the user signed in
redirectUri string The Uri of the application requesting the access token
resource string The resouce identifier of the target resource
return Task
        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;
            }
        }