Closed mwenko closed 2 years ago
Hi @mwenko 👋,
Thanks for opening this issue. Out of curiosity, is there a requirement/reason to use amazon-cognito-identity-js
and not Amplify Auth?
Hi @mwenko 👋,
Thanks for opening this issue. Out of curiosity, is there a requirement/reason to use
amazon-cognito-identity-js
and not Amplify Auth?
Hi @nadetastic
There is no specific reason.
But as Amplify Auth uses amazon-cognito-identity-js
under the hood, using it probably wouldn't solve this issue.
@mwenko We have created a streamlined experience for our developers needing to use Authentication with Cognito using the Authentication library from Amplify, and recommend using Amplify Auth instead of the cognito-identity-js library.
While we do provide some occasional fixes/upgrades to the cognito-identity-js library, we are planning on deprecating that package in the near future.
With Amplify Auth, you can use Auth.currentSession()
[1] to automatically refresh sessions.
You can opt in to use just the JS library without the Amplify CLI (https://docs.amplify.aws/lib/auth/start/q/platform/js/#re-use-existing-authentication-resource) if you feel like that would be better for your use case.
@mwenko It seems that you are expecting the refreshToken
to be refreshed, which to my understanding is not how OAuth works. The refreshToken
has a permanent expiration date and when it expires, the user has to re-authenticate before they can receive a new refreshToken
with a new expiration date. During the period when the refreshToken
is not yet expired, calling refreshSession
will generate a new accessToken
with an updated expiration date, but the refreshToken
never changes.
@mwenko following up on this, do you have any additional questions?
@mwenko We have created a streamlined experience for our developers needing to use Authentication with Cognito using the Authentication library from Amplify, and recommend using Amplify Auth instead of the cognito-identity-js library.
While we do provide some occasional fixes/upgrades to the cognito-identity-js library, we are planning on deprecating that package in the near future.
With Amplify Auth, you can use
Auth.currentSession()
[1] to automatically refresh sessions.You can opt in to use just the JS library without the Amplify CLI (https://docs.amplify.aws/lib/auth/start/q/platform/js/#re-use-existing-authentication-resource) if you feel like that would be better for your use case.
I'm gonna try Amplify Auth
and see if this solves my issue. Thanks also to @nadetastic for providing further information. I just don't wanna logout my users if they are active on a daily basis. I expect them to stay logged-in basically forever, like in all other common apps, like facebook, whatsapp, ...
@mwenko Sounds good, I'll go ahead and close this issue out. If you have any questions with using Amplify Auth, feel free open a new issue.
Amplify Auth does not resolve the described issue, as it uses the same API (https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html with AuthFlow=REFRESH_TOKEN_AUTH
.
This is another issue that is reported in the github issues of client facing libraries (such as amplify-js), but is a server-side bug.
I suspect that this bug is forcing many developers to extend the lifetime of the refresh token to multiple users. Does the AWS/Cognito team not perceive this as a security threat for their customers? Especially, as one can now assume that most apps using cognito work with multi-year refresh tokens? I am not a security expert, so some guidance on the implications of using a multi-year refresh token would be greatly appreciated!
Should we report this bug once again directly in the AWS console, or how do we get a timeline or any insight on a potential update? Usually any cognito bugs die silently with a comment of "we are forwarding this to the cognito team", such as this (unrelated) ticket from a while back.
I'll write down just for the record. I believe this issue end up updating LocalStorage with empty value, and later on, when Auth.currentSession()
is called, the app crashes.
I am in the middle of an investigation right now and couldn't make time to create reproducible example. Just wanted to share in case someone else is also facing this.
Log:
[DEBUG] 02:40.377 AuthClass - Getting current session
ConsoleLogger.ts:125 [DEBUG] 02:40.378 AuthClass - Failed to get the user session Error: Cannot retrieve a new session. Please authenticate.
at CognitoUser2.getSession (CognitoUser.js:1320:25)
at AuthClass2.<anonymous> (Auth.ts:1634:11)
at step (Errors.ts:117:29)
at Object.next (Errors.ts:117:29)
at Errors.ts:117:29
at new Promise (<anonymous>)
at __awaiter3 (Errors.ts:117:29)
at Auth.ts:1590:11
ConsoleLogger.ts:125 [DEBUG] 02:40.379 AuthClass - Failed to get the current user Error: Cannot retrieve a new session. Please authenticate.
at CognitoUser2.getSession (CognitoUser.js:1320:25)
at AuthClass2.<anonymous> (Auth.ts:1634:11)
at step (Errors.ts:117:29)
at Object.next (Errors.ts:117:29)
at Errors.ts:117:29
at new Promise (<anonymous>)
at __awaiter3 (Errors.ts:117:29)
at Auth.ts:1590:11
try {
await Auth.currentSession()
} catch (error) {
// handle the issue here. For example:
Auth.signOut()
}
Before opening, please confirm:
JavaScript Framework
Not applicable
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
I'm using
amazon-cognito-identity-js
to refresh theAccessToken
of a user. When executing therefreshSession
function (CognitoUser
) ofamazon-cognito-identity-js
theAccessToken
&IdToken
gets updated, but theRefreshToken
property is not present in theAuthenticationResult
.Looking at the documentation https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html the response definitely should include a
RefreshToken
as well.I debugged the
refreshSession
ofamazon-cognito-identity-js
and I don't get any newRefreshToken
from it.This is bad because if the
RefreshToken
never gets updated, we need to force the user to do a login (username + password) every time it expires. This is something that nobody likes.I found a few related issues that are describing the same issue: https://github.com/aws/aws-sdk-js/issues/4156 https://stackoverflow.com/questions/55069851/how-to-get-refresh-token-auth-request-to-return-refreshtoken https://www.reddit.com/r/aws/comments/g0pkcd/how_to_renew_refreshtoken_in_cognito/
This seems like a bug in the API?
Expected behavior
Each time
refreshSession
is called it should give back an updatedRefreshToken
with an updated expirationTime (which is configured inCognitoUserPool
.Reproduction steps
1) Installing
amazon-cognito-identity-js
2) CallingrefreshSession()
with valid paramters 3)RefreshToken
that is passed back in the result is the same as the one in the requestCode Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response