amazon-cognito-identity-js icon indicating copy to clipboard operation
amazon-cognito-identity-js copied to clipboard

After successful registration and confirming with registration code, how do we make user auto login without having him to enter the login details again.

Open shreynpatel274 opened this issue 7 years ago • 26 comments

In our registration flow we do the following

  1. Ask user to enter his details and do signup - which would make AWS call userPool.signUp()
  2. Show a popup to enter confirmation code which is sent to his email -- to confirm the code we call cognitoUser.confirmRegistration()

Now once the registration is confirmed, we want to retrieve the user attributes and use them for his session. But it looks like the session is not created for the user after successful registration and confirmation. userpool.getCurrentUser() - return null.

Is there a way to get the current registered user session, without having him login again?

shreynpatel274 avatar Oct 23 '16 10:10 shreynpatel274

The only way you can do this is by doing the authentication for user behind the scenes.

From the SignUp page, you already have user's username and password in the app context. You can just use those values to create a new CognitoUser and then calling authenticateUser on the user object onSuccess of the user confirmation. On authentication success, userPool.getCurrentUser should return you the logged in user.

chetanme avatar Oct 24 '16 06:10 chetanme

can you explain further as to how to go about implementing login sessions in the web application? Should the cognitouser object/tokens be saved as cookies or local storage in the web browser and have them submitted with every request?

hfougere avatar Nov 05 '16 00:11 hfougere

At this point, it is not possible to return tokens immediately after the user has signed up and confirmed the registration. We are considering the change such that the user doesn't need to authenticate after registering and confirming registration.

As for the other question, the logins are stored in local storage upon authentication and cleared when signing out so retrieving them across pages should be handled by use case 16 in the Readme file.

itrestian avatar Nov 05 '16 00:11 itrestian

Thanks, I am now able to use the get session method to reauthenticate (use case 16). However its seems that this only works if i'm actively making these calls. If I do not call getsession for an extended period, the get session method does not reauthenticate and the session again becomes invalid. How can I extend the period that I can use getsession (or any other method to refresh the session) so the user will not have to reauthenticate for say 2 weeks, or a month? Is there a parameter I can use somewhere?

hfougere avatar Nov 10 '16 14:11 hfougere

That would be the access token expiring, which is expected. That duration is one hour, and is not currently configurable. The refresh token is used to get a new access token during that getSession call (if need be), and it's valid for a much longer time by default.

The validity of the refresh token can be configured from the Cognito console, if desired, but the access token is only an hour.

jbailey2010 avatar Nov 10 '16 18:11 jbailey2010

Also, in terms of security... what's to stop someone from signing up a bunch of fake accounts since the userpool, client and identity pool ids are all easily accessible on the front end? It would be more work for them to confirm each of course. Is there a way to restrict where the requests are coming from (i.e ensure they can only be requested from my domain or my development ip address)?

hfougere avatar Nov 21 '16 21:11 hfougere

Doing the authentication for user behind the scenes means you might have to store the user credentials somewhere (e.g. local storage or in-memory). This might introduce security vulnerability. User doesn't need to authenticate after registering and confirming registration is highly desirable and please have it as soon as possible.

goldenbearkin avatar Jan 25 '17 14:01 goldenbearkin

Adding a plus one to this request.

thrichards avatar Feb 21 '17 18:02 thrichards

In regards to my comment from Nov 21, 2016, is there any way to move this up in priority as more than just an enhancement? Anyone can call the admin confirm function on an account with the public id. Can we have a separate issue for this? At the very lease we should have a way to restrict api calls to come from specific domains or IPs we control.

hfougere avatar Apr 03 '17 18:04 hfougere

+1, I really need this feature on my app, for now I am temporary saving the password and that's super insecure.

kevinwolfcr avatar Apr 18 '17 01:04 kevinwolfcr

+1 to this request.

UlisesCabrera avatar Jul 31 '17 13:07 UlisesCabrera

+1

scheler avatar Aug 21 '17 04:08 scheler

This is extremely important. Its annoying to have them login again.

nishiltamboli avatar Sep 16 '17 06:09 nishiltamboli

+1 should not have been open for so long

jurriaanr avatar Sep 22 '17 16:09 jurriaanr

Please resolve the issue soon. Not able to get the session after confirm signUp.

deblinaalways avatar Oct 02 '17 08:10 deblinaalways

+1

trecouvr avatar Oct 11 '17 05:10 trecouvr

I have resolved this issue after putting lot of time into it. Please follow the resolution steps mentioned below. This is for iOS integration.

  1. Update pod 'AWSCognito' and 'AWSCognitoIdentityProvider'.
  2. Sign up with userName, password and userAttributes. In the success response, acquire userSub from AWSCognitoIdentityUserPoolSignUpResponse. (In the earlier version there was a bug where AWSCognitoIdentityUserPoolSignUpResponse was not giving userSub.)
  3. If result is not confirmed state, land into OTP validation UI Screen and pass the 'userSub' and "password", "userName" into it. (In the following steps, you will come to know why password has been passed.)
  4. Call 'confirmSignUp' with the OTP you have received.
  5. If it is success, get cognitoUser from pool.getUser("userName").
  6. Call getSession("userName", password: "password"). (Do not call getSession() function which will land you up to Sign In UI Screen.).
  7. In the success response 'AWSCognitoIdentityUserSession', you will receive 'idToken', 'accessToken' and 'expirationTime'. You can use it according to the need. getSession is useful when idToken gets expired.

The only problem what I faced is that I have to save the password locally (encrypt it and save.) to getSession with 'userName' and 'password' to avoid the sign in UI Screen to show.

I hope, this resolution gonna save lot of time for a time being for you guys until aws sdk gets updated where we don't have to save the password. Thanks.

deblinaalways avatar Oct 11 '17 05:10 deblinaalways

+1 this feature is very much desired

youanswer avatar Oct 23 '17 11:10 youanswer

+1

vedtam avatar Oct 31 '17 17:10 vedtam

Everyone commenting with "+1" should know that GitHub has a +1 reaction you can give to the original request which goes much further in terms of prioritizing an item as companies can do reports on issues sorted by +1 reactions, not comments.

et304383 avatar Nov 27 '17 14:11 et304383

+1

ghost avatar Dec 08 '17 22:12 ghost

+1

deblinaalways avatar Dec 09 '17 01:12 deblinaalways

@lourdesmm90 @deblinaalways @shishiranshuman13 is this a joke? You're literally commenting with a +1 after a post about why +1 comments are useless and just create unnecessary emails to those watching the issue.

et304383 avatar Feb 01 '18 12:02 et304383

@et304383 You only said, "Everyone commenting with "+1" should know that GitHub has a +1 reaction you can give to the original request which goes much further in terms of prioritizing an item as companies can do reports on issues sorted by +1 reactions, not comments." Your comments are contradictory dude!! Were you joking?

deblinaalways avatar Feb 01 '18 12:02 deblinaalways

@et304383 If this bothers you so much I'll remove the comment and add a reaction instead. But please be polite in your comments.

shishiranshuman avatar Feb 01 '18 14:02 shishiranshuman

Anyway, back to the issue.

https://github.com/aws/amazon-cognito-identity-js/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc

@itrestian this is the most +1'd feature in your issue list yet it's been over a year with no enhancement. Why is this not at the top of the priority list for the Cognito JS team?

et304383 avatar Feb 01 '18 14:02 et304383