-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user.sendCustomChallengeAnswer is not a function #3373
Comments
@jinjunho Hi, can you provide more info like:
|
Hi @powerful23, thank you for paying attention to my question.
Short version Two user objects, one from Long version // app.js
...
app.use(session({
secret: "my-secret-string",
resave: false,
saveUninitialized: true
}))
...
// router/auth.js
...
router.post("/login", (req, res) => {
...
// This function is passed to login function in Solution 1.
// login function in Solution 1 passes user object returned by Auth.signIn to this function.
function resolve(user) {
// First user object check
console.log(user)
req.session.username = username
req.session.user = user
res.status(httpStatus.OK).send()
}
...
})
...
router.post("/verification/login", (req, res) => {
...
// Second user object check
console.log(req.session.user)
}
... I printed user object two times: first I checked right after Here is the result: // First check
2019-06-01 07:52:27.646 +09:00: CognitoUser {
2019-06-01 07:52:27.646 +09:00: username: '...some string...',
2019-06-01 07:52:27.646 +09:00: pool:
2019-06-01 07:52:27.646 +09:00: CognitoUserPool {
2019-06-01 07:52:27.646 +09:00: userPoolId: '...some string...',
2019-06-01 07:52:27.646 +09:00: clientId: '...some string...',
2019-06-01 07:52:27.646 +09:00: client:
2019-06-01 07:52:27.646 +09:00: Client {
2019-06-01 07:52:27.646 +09:00: endpoint: '...some string...',
2019-06-01 07:52:27.646 +09:00: userAgent: 'aws-amplify/0.1.x js' },
2019-06-01 07:52:27.646 +09:00: advancedSecurityDataCollectionFlag: true,
2019-06-01 07:52:27.646 +09:00: storage:
2019-06-01 07:52:27.646 +09:00: { [Function: MemoryStorage]
2019-06-01 07:52:27.646 +09:00: setItem: [Function],
2019-06-01 07:52:27.646 +09:00: getItem: [Function],
2019-06-01 07:52:27.646 +09:00: removeItem: [Function],
2019-06-01 07:52:27.646 +09:00: clear: [Function] } },
2019-06-01 07:52:27.646 +09:00: Session: '...some string...',
2019-06-01 07:52:27.646 +09:00: client:
2019-06-01 07:52:27.646 +09:00: Client {
2019-06-01 07:52:27.646 +09:00: endpoint: 'https://cognito-idp.ap-southeast-1.amazonaws.com/',
2019-06-01 07:52:27.646 +09:00: userAgent: 'aws-amplify/0.1.x js' },
2019-06-01 07:52:27.646 +09:00: signInUserSession: null,
2019-06-01 07:52:27.646 +09:00: authenticationFlowType: 'CUSTOM_AUTH',
2019-06-01 07:52:27.646 +09:00: storage:
2019-06-01 07:52:27.646 +09:00: { [Function: MemoryStorage]
2019-06-01 07:52:27.646 +09:00: setItem: [Function],
2019-06-01 07:52:27.646 +09:00: getItem: [Function],
2019-06-01 07:52:27.646 +09:00: removeItem: [Function],
2019-06-01 07:52:27.646 +09:00: clear: [Function] },
2019-06-01 07:52:27.646 +09:00: keyPrefix: '...some string...',
2019-06-01 07:52:27.646 +09:00: userDataKey:
2019-06-01 07:52:27.646 +09:00: '...some string...',
2019-06-01 07:52:27.646 +09:00: challengeName: 'CUSTOM_CHALLENGE',
2019-06-01 07:52:27.646 +09:00: challengeParam: {} }
// Second check
2019-06-01 07:43:31.043 +09:00: { username: '...some string...',
2019-06-01 07:43:31.043 +09:00: pool:
2019-06-01 07:43:31.043 +09:00: { userPoolId: '...some string...',
2019-06-01 07:43:31.043 +09:00: clientId: '...some string...',
2019-06-01 07:43:31.043 +09:00: client:
2019-06-01 07:43:31.043 +09:00: { endpoint: '...some string...',
2019-06-01 07:43:31.043 +09:00: userAgent: 'aws-amplify/0.1.x js' },
2019-06-01 07:43:31.043 +09:00: advancedSecurityDataCollectionFlag: true },
2019-06-01 07:43:31.043 +09:00: Session: '...some string...',
2019-06-01 07:43:31.043 +09:00: client:
2019-06-01 07:43:31.043 +09:00: { endpoint: 'https://cognito-idp.ap-southeast-1.amazonaws.com/',
2019-06-01 07:43:31.043 +09:00: userAgent: 'aws-amplify/0.1.x js' },
2019-06-01 07:43:31.043 +09:00: signInUserSession: null,
2019-06-01 07:43:31.043 +09:00: authenticationFlowType: 'CUSTOM_AUTH',
2019-06-01 07:43:31.043 +09:00: keyPrefix: '...some string...',
2019-06-01 07:43:31.043 +09:00: userDataKey:
2019-06-01 07:43:31.043 +09:00: '...some string...',
2019-06-01 07:43:31.043 +09:00: challengeName: 'CUSTOM_CHALLENGE',
2019-06-01 07:43:31.043 +09:00: challengeParam: {} } You can ignore Would you help me to understand why this happens and to fix this issue?
notice You mentioned
I simply retrieved For better understanding, here's the code I used: // router/auth.js
...
router.post("/login", (req, res) => {
...
// This function is passed to login function in Solution 1.
// login function in Solution 1 passes user object returned by Auth.signIn to this function.
function resolve(user) {
req.session.username = username
req.session.user_session = user.Session
res.status(httpStatus.OK).send()
}
...
})
...
router.post("/verification/login", (req, res) => {
...
// req.session.user_session remains same in express-session
console.log(req.session.user_session)
}
... |
I managed to make it work by creating new Here's the new code sample that works: // Authentication Helper
...
constructor() {
...
// This is temporary store for user objects
this.tempSession = {}
...
}
...
login(username, password, resolve, reject) {
Auth.signIn(username, password)
.then(user => {
if (user.challengeName === "CUSTOM_CHALLENGE") {
// Keep user object
this.tempSession[username] = user
resolve(user)
} else {
reject()
}
})
.catch(error => {
// Handling error...
})
}
...
verifyLoginTrial(username, code, resolve, reject) {
const user = this.tempSession[username]
Auth.sendCustomChallengeAnswer(user, code)
.then(signedUser => {
// It works
console.log(signedUser)
// Flush user object
delete this.tempSession[username]
resolve(signedUser)
})
.catch(error => {
// Handling error...
})
} This solution works anyway. However, I'm not comfortable with this approach, it just feels too hacky. comment I was suspicious about |
@jinjunho Hi, For the first question I think it's because For the second one I think you are doing correctly by storing the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Our requirement was also the same and we managed to get the customAuth flow working by creating cognitoUserPool and cognitoUser instance from localStorage/sessionStorage before calling sendCustomChallengeAnswer. Example:
|
@hitenkaram It's on clientside, right? |
Sorry for the late response, I thought I already replied back as soon as I got the query notification. |
i am still having the same problem , when i sign in from API with custom_auth and try to send the custom challenge ans from different api its always giving me response user.sendCustomChallengeAnswer |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
i got the answer for back end code : i have to use aws-sdk for customer_auth challenge answer , its was hard to find from the function cz, no documentation is available for it |
My server side use PKCE for authentication, they also give us some code snippet related to this function user.sendCustomChallengeAnswer, but i found that this is for JS. |
Amplify JS doesnt currently support Node.js @tantai24495 with regards to the Android SDK could you open an issue on their github repo: https://github.com/aws-amplify/aws-sdk-android If you have additional questions/issues please open a new one |
did you implement that in client side ? how does the amplify framework store the session after sendCUstomChallengeAnswer? In my case, with CUSTOM_AUTH, a otp is triggered to email after i signin without password..and then i confirm the otp using sendChallengeAnswer() . But After this the session is not persisted by Auth, so whenever i call Auth.currentAuthenticatedUser() it returns null always..so now if i reload my app it ask me to login again .. whats the way to store session ? |
@ajit100 I am having the same issue, did you find any solution? thanks! |
I was facing the same issue, and according to what I could see on my IDE, the function existed, but I was still getting that error message. But I realized the The error message is misleading! I recommend logging both of the parameters you're passing to the function to make sure you're passing correct data to the function |
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 |
This is a long article but organized pretty neat. Please read it and help me if you have any clue.
It's easy to reproduce using simple express application.
(just separate Auth.signIn and Auth.sendCustomChallengeAnswer in different router)
Notice
Similar symptom found in old issue(#1896), but it seems to be happening in frontend, while I'm having it in backend.
=======
Which Category is your question related to?
: Usage Question
What AWS Services are you utilizing?
Cognito with Amplify Auth
Provide additional details e.g. code snippets
Current situation
I'm implementing Auth.signIn in express based Node.js REST API server.
(Please note that this is backend application, not frontend such as react or angular).
So far, I've successfully implemented Auth.signUp, Auth.confirmSignUp and Auth.signIn.
For custom MFA (sending verification code to user's email), I'm using CUSTOM_AUTH and my lambda functions bound to Cognito user pool are successfully triggered.
Currently implemented features(Auth.signUp, Auth.confirmSignUp and Auth.signIn) were implemented in separated endpoints(i.e., those Auth methods are called by different REST APIs), so as Auth.sendCustomChallengeAnswer that I'm having trouble with.
Problem
Trial 1
login
code snippet I'm using now:login verification
:Trial 2
Same code for
login
This time, I've tried manually creating CognitoUser but it also didn't work.
Question
Thank you for reading this long question.
The text was updated successfully, but these errors were encountered: