Exemple #1
0
        public async Task <IActionResult> OnGetAsync(bool rememberMe, string returnUrl = null)
        {
            // Ensure the user has gone through the username & password screen first
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                throw new InvalidOperationException($"Unable to load two-factor authentication user.");
            }

            ReturnUrl  = returnUrl;
            RememberMe = rememberMe;

            return(Page());
        }
        public async void Test_GivenAUserSignedInWith2FAContext_WhenGetTwoFactorAuthenticationUser_ThenTheUserIsRetrieved()
        {
            var cognitoUser = GetCognitoUser();

            var context = MockUtils.MockContext(cognitoUser, IdentityConstants.TwoFactorUserIdScheme);

            contextAccessorMock.Setup(a => a.HttpContext).Returns(context).Verifiable();
            userManagerMock.Setup(mock => mock.FindByIdAsync(It.IsAny <string>())).Returns(Task.FromResult(cognitoUser)).Verifiable();

            var output = await signinManager.GetTwoFactorAuthenticationUserAsync().ConfigureAwait(false);

            Assert.Equal(cognitoUser, output);
            contextAccessorMock.Verify();
            userManagerMock.Verify();
        }