{"action":"created","issue":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1812","repository_url":"https://api.github.com/repos/aws-amplify/amplify-js","labels_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1812/labels{/name}","comments_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1812/comments","events_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1812/events","html_url":"https://github.com/aws-amplify/amplify-js/issues/1812","id":365876475,"node_id":"MDU6SXNzdWUzNjU4NzY0NzU=","number":1812,"title":"AWS Cognito optional TOTP MFA error \"Unknown error, the response body from fetch is: undefined\"","user":{"login":"mattbryce93","id":19416715,"node_id":"MDQ6VXNlcjE5NDE2NzE1","avatar_url":"https://avatars3.githubusercontent.com/u/19416715?v=4","gravatar_id":"","url":"https://api.github.com/users/mattbryce93","html_url":"https://github.com/mattbryce93","followers_url":"https://api.github.com/users/mattbryce93/followers","following_url":"https://api.github.com/users/mattbryce93/following{/other_user}","gists_url":"https://api.github.com/users/mattbryce93/gists{/gist_id}","starred_url":"https://api.github.com/users/mattbryce93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattbryce93/subscriptions","organizations_url":"https://api.github.com/users/mattbryce93/orgs","repos_url":"https://api.github.com/users/mattbryce93/repos","events_url":"https://api.github.com/users/mattbryce93/events{/privacy}","received_events_url":"https://api.github.com/users/mattbryce93/received_events","type":"User","site_admin":false},"labels":[{"id":881545386,"node_id":"MDU6TGFiZWw4ODE1NDUzODY=","url":"https://api.github.com/repos/aws-amplify/amplify-js/labels/Cognito","name":"Cognito","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-02T12:35:10Z","updated_at":"2018-10-03T09:11:02Z","closed_at":null,"author_association":"NONE","body":"** Which Category is your question related to? **\r\namazon-cognito-identity-js\r\n** What AWS Services are you utilizing? **\r\nCognito User Pool\r\n** Provide additional details e.g. code snippets **\r\nI am attempting to get TOTP MFA working with my User Pools. The issue I am running into is that I want to have the MFA set to optional. This is the code that handles the authentication:\r\n\r\n```\r\nconst classThis = this;\r\n    cognitoUser.authenticateUser(authenticationDetails, {\r\n      onSuccess: function (result) {\r\n        const accessToken = result.getAccessToken().getJwtToken();\r\n        console.log('Signed in Successfully');\r\n        // here would be the redirection to the internal systems as authentication has been successful at this point\r\n        if (classThis.enableMFA) {\r\n          cognitoUser.associateSoftwareToken(this);\r\n        }\r\n      },\r\n\r\n      onFailure: function(err) {\r\n        console.log(err.message);\r\n      },\r\n\r\n      mfaSetup: function(challengeName, challengeParameters) {\r\n        cognitoUser.associateSoftwareToken(this);\r\n      },\r\n      // @ts-ignore\r\n      associateSecretCode : function(secretCode) {\r\n        classThis.qrCode = secretCode;\r\n        classThis.showTOTPVerification = true;\r\n        classThis.totpVerify.subscribe(challengeAnswer => {\r\n          console.log('verifying Software Token');\r\n          cognitoUser.verifySoftwareToken(challengeAnswer, 'My TOTP device', this);\r\n        });\r\n      },\r\n\r\n      selectMFAType : function(challengeName, challengeParameters) {\r\n        const mfaType = prompt('Please select the MFA method.', ''); // valid values for mfaType is \"SMS_MFA\", \"SOFTWARE_TOKEN_MFA\"\r\n        // @ts-ignore\r\n        cognitoUser.sendMFASelectionAnswer(mfaType, this);\r\n      },\r\n\r\n      totpRequired : function(secretCode) {\r\n        console.log('mfaRequired');\r\n        classThis.showTOTPVerification = true;\r\n        classThis.totpVerify.subscribe(verificationCode => {\r\n          console.log('sending MFA Token');\r\n          cognitoUser.sendMFACode(verificationCode, this, 'SOFTWARE_TOKEN_MFA');\r\n        });\r\n      },\r\n\r\n      mfaRequired: function (codeDeliveryDetails) {\r\n        console.log('mfaRequired');\r\n        classThis.showTOTPVerification = true;\r\n        // const verificationCode = prompt('Please input verification code', '');\r\n        // SOFTWARE_TOKEN_MFA is set here as sendMFACode defaults to SMS MFA by default\r\n        classThis.totpVerify.subscribe(verificationCode => {\r\n          console.log('sending MFA Token');\r\n          cognitoUser.sendMFACode(verificationCode, this, 'SOFTWARE_TOKEN_MFA');\r\n        });\r\n      },\r\n    });\r\n  }\r\n```\r\nCurrently, authentication works perfectly if the MFA is set to required. When set to optional, authentication works but the mfaSetup flag is never triggered. Which is why I added the lines:\r\n```\r\nif (classThis.enableMFA) {\r\n          cognitoUser.associateSoftwareToken(this);\r\n        }\r\n```\r\nWithin the OnSuccess block. I can trigger the associateSoftwareToken in this but the error I receive is \"Unknown error, the response body from fetch is: undefined\". Which indicates to me that I am missing a block within the authenticate User flow. The fetch returned the following key value pair which I think is a hint but have been unable to find much information with it:\r\n```\r\nChallengeName: \"PASSWORD_VERIFIER\"\r\n```\r\nHas anyone came across this as the documentation is rather limited when it comes to TOTP authentication? \r\n\r\nIf it was necessary to pass something into the authenticateUser to trigger the mfaSetup that would be awesome. But if I am simply missing a definition then I'd be grateful to be pointed in the right direction."},"comment":{"url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/comments/426565332","html_url":"https://github.com/aws-amplify/amplify-js/issues/1812#issuecomment-426565332","issue_url":"https://api.github.com/repos/aws-amplify/amplify-js/issues/1812","id":426565332,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNjU2NTMzMg==","user":{"login":"mattbryce93","id":19416715,"node_id":"MDQ6VXNlcjE5NDE2NzE1","avatar_url":"https://avatars3.githubusercontent.com/u/19416715?v=4","gravatar_id":"","url":"https://api.github.com/users/mattbryce93","html_url":"https://github.com/mattbryce93","followers_url":"https://api.github.com/users/mattbryce93/followers","following_url":"https://api.github.com/users/mattbryce93/following{/other_user}","gists_url":"https://api.github.com/users/mattbryce93/gists{/gist_id}","starred_url":"https://api.github.com/users/mattbryce93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattbryce93/subscriptions","organizations_url":"https://api.github.com/users/mattbryce93/orgs","repos_url":"https://api.github.com/users/mattbryce93/repos","events_url":"https://api.github.com/users/mattbryce93/events{/privacy}","received_events_url":"https://api.github.com/users/mattbryce93/received_events","type":"User","site_admin":false},"created_at":"2018-10-03T09:11:02Z","updated_at":"2018-10-03T09:11:02Z","author_association":"NONE","body":"I have done more investigation and on the response after trying to verify my token the response gives:\r\n```\r\n{\"Status\":\"SUCCESS\"}\r\n```\r\nAnd after testing the login after running a function to change the users MFA preferences:\r\n```\r\nsetupMFA() {\r\n    const cognitoUser = this.userPool.getCurrentUser();\r\n\r\n    if (cognitoUser != null) {\r\n      cognitoUser.getSession(function(err, session) {\r\n          if (err) {\r\n            console.log(err);\r\n            return;\r\n          }\r\n          // console.log('session validity: ' + session.isValid());\r\n          const totpMfaSettings = {\r\n            PreferredMfa : true,\r\n            Enabled : true\r\n          };\r\n          cognitoUser.setUserMfaPreference(null, totpMfaSettings, function(err, result) {\r\n              if (err) {\r\n                console.log(err);\r\n              }\r\n              console.log('call result ' + result);\r\n          });\r\n        });\r\n      console.log('Setting up MFA');\r\n    } else {\r\n      console.log('There is no current User Session');\r\n    }\r\n  }\r\n```\r\nThey are now required to use the TOTP software token. The only issue is that my code is not ingesting that Success response correctly to take it to the onSuccess function block."}}
{"actor":{"display_login":"mattbryce93"}}