Skip to content
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

Refreshing access token #42

Closed
adamjv90 opened this issue Dec 6, 2017 · 9 comments
Closed

Refreshing access token #42

adamjv90 opened this issue Dec 6, 2017 · 9 comments
Labels
Auth Related to Auth components/category feature-request Request a new feature

Comments

@adamjv90
Copy link

adamjv90 commented Dec 6, 2017

Is the access token automatically refreshed as documented here http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html#amazon-cognito-user-pools-using-the-refresh-token . If so what is the recommended way of subscribing to refreshed access token?

@mlabieniec mlabieniec added the question General question label Dec 7, 2017
@richardzcode
Copy link
Contributor

At anytime you can get current session which contains current valid access token. Issue 37 has an example on idToken

const options = {
    headers: {
      Authorization: Auth.currentSession().idToken.jwtToken      
    }
  }
  return await API.get(name, '/path', options);

Thanks,
Richard

@mlabieniec
Copy link
Contributor

@adamjv90 currently there is not a way of "subscribing" to the token refresh, it occurs automatically. This method will automatically refresh your credentials if they are expired.

Would your use case be to have the ability to subscribe to this at an interval or provided time (1 hour before etc.) or would you want to be notified when they are expired?

@timotgl
Copy link

timotgl commented Feb 28, 2018

@mlabieniec I might have a similar use case, we're using the accessToken to make requests to a backend (which is hooked into the same cognito user pool). But since we copy the JWT to another place in the frontend for this, we would use an expired token after a while - If I understand this correctly.

What would be the recommended way to use an up-to-date token without having the fetch the cognito session every time we talk to the other backend?

@mlabieniec mlabieniec added enhancement and removed question General question labels Feb 28, 2018
@mlabieniec mlabieniec reopened this Feb 28, 2018
@timotgl
Copy link

timotgl commented Mar 1, 2018

@mlabieniec Thanks for reopening the issue. Being notified when the token has changed would be perfect.

https://github.com/aws/aws-amplify/blob/master/packages/aws-amplify/src/Auth/Auth.ts#L872 seems to suggest that the refresh happens when the token would expire in under 10 minutes? Does this require active use of the library or is it polling on its own with a set interval?

@mlabieniec
Copy link
Contributor

@timotgl there is no polling right now. Currently it just checks and refreshes when an API method or any other method that requires credentials is called (prior) with the keepAlive method. What we can do is use the Hub dispatcher (light weight pub/sub utility within amplify) to dispatch (and allow subscription to) an event and use an interval for this feature which would dispatch it N minutes before expiration.

@powerful23
Copy link
Contributor

Closing as Amplify now will automatically refresh the session. https://github.com/aws/aws-amplify/wiki/FAQ

@CHR15-
Copy link

CHR15- commented Aug 10, 2018

@mlabieniec If we need to sign sig4 manually, is there a way to subscribe to the JWT refresh?

@usmansbk
Copy link

usmansbk commented Jan 20, 2019

It seems refreshing Google token only works automatically in browser environments. It doesn't work on react-native apps except for Expo maybe.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Auth Related to Auth components/category feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

7 participants