in src/Amazon.AspNetCore.Identity.Cognito/CognitoSigninManager.cs [346:385]
public async Task<SignInResult> RespondToTwoFactorChallengeAsync(string code, bool isPersistent, bool rememberClient)
{
var twoFactorInfo = await RetrieveTwoFactorInfoAsync().ConfigureAwait(false);
if (twoFactorInfo == null || string.IsNullOrWhiteSpace(twoFactorInfo.UserId))
{
return SignInResult.Failed;
}
var user = await _userManager.FindByIdAsync(twoFactorInfo.UserId).ConfigureAwait(false);
if (user == null)
{
return SignInResult.Failed;
}
// Responding to the Cognito challenge.
await _userManager.RespondToTwoFactorChallengeAsync(user, code, twoFactorInfo.ChallengeNameType, twoFactorInfo.CognitoAuthenticationWorkflowId).ConfigureAwait(false);
if (user.SessionTokens == null || !user.SessionTokens.IsValid())
{
return SignInResult.Failed;
}
else
{
// Cleanup external cookie
if (twoFactorInfo.LoginProvider != null)
{
await Context.SignOutAsync(IdentityConstants.ExternalScheme).ConfigureAwait(false);
}
// Cleanup two factor user id cookie
await Context.SignOutAsync(IdentityConstants.TwoFactorUserIdScheme).ConfigureAwait(false);
if (rememberClient)
{
await RememberTwoFactorClientAsync(user).ConfigureAwait(false);
}
// This creates the ClaimPrincipal and signs in the user in the IdentityConstants.ApplicationScheme
await SignInAsync(user, isPersistent, twoFactorInfo.LoginProvider).ConfigureAwait(false);
return SignInResult.Success;
}
}