admin管理员组

文章数量:1296470

I am trying to implement a Remember Me option for authentication workflow using amazon-cognito-identity-js in Angular2 project. Issue reference.

Current authentication flow

  1. If Remember me option is checked then save token and JWT token(specially do this because I need some other user info such as groups and roles) to cookie with expiration date. (ex : 5 days )
  2. Auth guard (that is checking all routing changes even if root routing) will check token(not JWT) first
  3. If cookie is empty then redirect to Login page.
  4. If cookie exists then check session(using function of sdk), session is invalid then redirect to Login page.
  5. If session is valid then update JWT(not token) and guard returns true.

I think it seems fine, but I am getting some unexpected errors, not often but once 1 hour has passed (actual session expired).

Questions

  1. Do I have to update token as well? At step 5.
  2. Is this.cognitoUtil.getCurrentUser(); asynchronous function?
  3. What will be returned from cognitoUser.getSession() if session is expired?
  4. If Ques 3 returns session (even if it is valid or invalid), what is the returning value of session.isValid()?

I am trying to implement a Remember Me option for authentication workflow using amazon-cognito-identity-js in Angular2 project. Issue reference.

Current authentication flow

  1. If Remember me option is checked then save token and JWT token(specially do this because I need some other user info such as groups and roles) to cookie with expiration date. (ex : 5 days )
  2. Auth guard (that is checking all routing changes even if root routing) will check token(not JWT) first
  3. If cookie is empty then redirect to Login page.
  4. If cookie exists then check session(using function of sdk), session is invalid then redirect to Login page.
  5. If session is valid then update JWT(not token) and guard returns true.

I think it seems fine, but I am getting some unexpected errors, not often but once 1 hour has passed (actual session expired).

Questions

  1. Do I have to update token as well? At step 5.
  2. Is this.cognitoUtil.getCurrentUser(); asynchronous function?
  3. What will be returned from cognitoUser.getSession() if session is expired?
  4. If Ques 3 returns session (even if it is valid or invalid), what is the returning value of session.isValid()?
Share Improve this question edited Jan 4, 2018 at 16:58 numaroth 1,3134 gold badges26 silver badges36 bronze badges asked Nov 2, 2017 at 2:35 Zhengzhe LiZhengzhe Li 1,83622 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5
  1. Yes. I mean I don't know what you mean by token & JWT token. In terms of Cognito tokens, there are id, access & refresh tokens. Id & access tokens expire in an hour & refresh token in 30 days (default). See this doc for reference.
  2. I don't think so. I mean amazon-cognito-identity-js SDK uses normal javascript SDKs and there getCurrentUser() just retrieves user from local storage.
  3. The SDKs will automatically try to refresh the id/access token using the refresh token (which is valid for 30 days by default).
  4. Returns boolean. See this SDK definition.

Cognito provides configuration for remembering devices from which user login.

You can find this configuration under devices menu in your user pool settings.

Basically three options are provided with question "Do you want to remember your user's devices?"

  1. Always - Cognito will always remember devices.
  2. User Opt In - Depends on user choice.
  3. NO - Never tracks devices.

For more details please visit this link - Here you will find implementation for the same. https://aws.amazon./blogs/mobile/tracking-and-remembering-devices-using-amazon-cognito-your-user-pools/

本文标签: javascriptHow to implement *Remember me* option using Amazon Cognito sdkStack Overflow