Custom Auth Flow Notworking
See original GitHub issueDescribe the bug Custom Auth Flow is not working. This is the error I receive from the console. Error: Authentication flow type is invalid. at CognitoUser.authenticateUser (CognitoUser.js:220) at Auth.js:432 at new ZoneAwarePromise (zone.js:891) at AuthClass.push…/node_modules/@aws-amplify/auth/lib/Auth.js.AuthClass.signInWithPassword (Auth.js:431) at AuthClass.push…/node_modules/@aws-amplify/auth/lib/Auth.js.AuthClass.signIn (Auth.js:323) at AuthClass.aws_amplify__WEBPACK_IMPORTED_MODULE_0___default.a.Auth.signIn (auth.decorator.js:34) at CustomAuthService.push…/src/@fuse/services/custom-auth-service.ts.CustomAuthService.login (custom-auth-service.ts:45) at LoginComponent.push…/src/app/main/pages/authentication/login/login.component.ts.LoginComponent.login (login.component.ts:68) at Object.eval [as handleEvent] (LoginComponent.html:13) at handleEvent (core.js:10258) To Reproduce Steps to reproduce the behavior:
- go to https://github.com/koolkav1/angular-custom-auth-flow-aws/blob/sample-branch/
- download the branch
- Set up your own Cognito with Custom Auth
- add Mobile Hub Credentials to aws-exports.ts
- ng serve --open and navigate to http://localhost:4200/pages/auth/login
Expected behavior A clear and concise description of what you expected to happen.
Being able to flow through the authentication pages effectively. Flow through the authentication
Sample code Lambda functions for the custom auth flow
// defineAuthChallenge
exports.handler = (event, context, callback) => {
// TODO implement
console.log("In lambda");
//callback(null, 'Hello from Lambda');
if(event.request.session.length === 0){
event.response.issueTokens = false;
event.response.failAuthentication = false;
event.response.challengeName = 'CUSTOM_CHALLENGE'
} else if(event.request.session.length === 1
&& event.request.session[0].challengeName === 'CUSTOM_CHALLENGE'
&& event.request.session[0].challengeResult === true){
event.response.issueTokens = true;
event.response.failAuthentication = false;
} else {
event.response.issueTokens = false;
event.response.failAuthentication = true;
}
callback(null, event);
};
// createAuth
console.log("Loading Function");
exports.handler = (event, context, callback) => {
if(event.request.session.length === 0
&& event.request.challengeName === 'CUSTOM_CHALLENGE'){
//CreateCode
let answer = '123456';
//Set the return parameters --Including correct answer
event.response.publicChallengeParameters = {};
event.response.privateChallengeParameters = {};
event.response.privateChallengeParameters.answer = answer;
event.response.challengeMetaData = 'PASSWORD_CHALLENGE';
}
callback(null, event);
};
//verifyAuth
exports.handler = (event, context, callback) => {
if(event.request.privateChallengeParameters.answer === event.request.challengeAnswer){
event.response.answerCorrect = true;
} else { event.response.answerCorrect = true;
}
callback(null, event);
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
Top GitHub Comments
Hey! I am currently encountering this same issue. I keep seeing the
authenticationFlowType:'CUSTOM_AUTH'
whenever I log out my console, but my app someone still usesUSER_SRP_AUTH
which is the default flow type. Were you able to find a solution to this issue please?This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.