I am attempting to implement a custom passwordless signup flow from the AWS Getting Started Documentation. I am nearly there, and on the last step it fails. I am unable to get Cognito to send a user an email containing a custom challenge after sign in. All other aspects of the authentication system work fine.
Here is my signin code:
func signIn(username: String) { Amplify.Auth.signIn(username: username, password: "bla") { [weak self] result in switch result { case .success (let result): if case .confirmSignInWithCustomChallenge(_) = result.nextStep { DispatchQueue.main.async { self?.showConfirmationSignInView() } } else { print("Sign in succeeded") } case .failure(let error): print("Sign in failed \(error)") } } } func customChallenge(response: String) { Amplify.Auth.confirmSignIn(challengeResponse: response) {[weak self] result in switch result { case .success: DispatchQueue.main.async { self?.getCurrentAuthUser() } print("Confirm sign in succeeded") case .failure(let error): print("Confirm sign in failed \(error)") } } } } And my lambda triggers are set up like so:
CREATAEAUTHCHALLENGE function createAuthChallenge(event) { if (event.request.challengeName === 'CUSTOM_CHALLENGE') { event.response.publicChallengeParameters = {}; event.response.privateChallengeParameters = {}; event.response.privateChallengeParameters.answer = process.env.CHALLENGEANSWER; } } exports.handler = (event, context, callback) => { createAuthChallenge(event); callback(null, event); }; DEFINEAUTHCHALLENGE
exports.handler = function(event, context) { if (event.request.session.length == 1 && event.request.session[0].challengeName == 'SRP_A') { event.response.issueTokens = false; event.response.failAuthentication = false; event.response.challengeName = 'CUSTOM_CHALLENGE'; } else if (event.request.session.length == 2 && event.request.session[1].challengeName == 'CUSTOM_CHALLENGE' && event.request.session[1].challengeResult == true) { event.response.issueTokens = true; event.response.failAuthentication = false; event.response.challengeName = 'CUSTOM_CHALLENGE'; } else { event.response.issueTokens = false; event.response.failAuthentication = true; } context.done(null, event); } VERIFYCHALLENGE
function verifyAuthChallengeResponse(event) { if (event.request.privateChallengeParameters.answer === event.request.challengeAnswer) { event.response.answerCorrect = true; } else { event.response.answerCorrect = false; } } exports.handler = (event, context, callback) => { verifyAuthChallengeResponse(event); callback(null, event); }; Though the user is able to successfully confirm sign in if I simply hardcode the challenge response, an email is never received telling the user what the custom challenge is. Any help would be appreciated!
https://stackoverflow.com/questions/66485747/amplify-custom-challenge-never-sent March 05, 2021 at 10:07AM
没有评论:
发表评论