private async Task PopulateTokens()

in src/Amazon.AspNetCore.Identity.Cognito/CognitoUserManager.cs [145:170]


        private async Task PopulateTokens(TUser user, string claimType, string claimValue)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            // First check if the current user is authenticated before calling AuthenticateAsync() or the call may hang.
            if (_httpContextAccessor?.HttpContext?.User?.Identity?.IsAuthenticated == true)
            {
                var result = await _httpContextAccessor.HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme).ConfigureAwait(false);

                if (result?.Principal?.Claims != null)
                {
                    if (result.Principal.Claims.Any(claim => claim.Type == claimType && claim.Value == claimValue))
                    {
                        var accessToken = await _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).ConfigureAwait(false);
                        var refreshToken = await _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.RefreshToken).ConfigureAwait(false);
                        var idToken = await _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken).ConfigureAwait(false);

                        user.SessionTokens = new CognitoUserSession(idToken, accessToken, refreshToken, result.Properties.IssuedUtc.Value.UtcDateTime, result.Properties.ExpiresUtc.Value.UtcDateTime);
                    }
                }
            }           
        }