Closed tarciosaraiva closed 6 years ago
"Cache-Control: no-cache" makes me think that awsamplify has it's cache turned off... it's not storing the Refresh Token to use it later... that's just my first thought from a quick glance.
// OPTIONAL - Configuration for cookie storage
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - Cookie secure flag
secure: true
},
This part of the aws-amplify config.
@michaelcuneo not quite. LocalStorage has idToken + accessToken + refreshToken stored successfully. And the request POST data above contains the full refresh token.
We actually have a refresh token implementation using the aws-sdk happening in our back-end services and it works successfully.
I had a feeling my answer wasn't correct... I didn't look at it for long enough, but with the new information... I'm wondering why you have aws-sdk running alongside aws-amplify... what's the specific use case that's making you need to pull that in as well, I guess, you have a specific purpose for it that isn't covered in the aws-amplify API. Is there a sync between your local storage version of refresh token and the aws-amplify version of the refresh token so that when the access token expires it grabs a valid copy of the refresh token before requesting an access token?
@michaelcuneo OK let me provide a bit more insight into my setup:
aws-amplify
as a dependencyaws-sdk
as a dependencyTL;DR the back-end reads the tokens from Cookies setup by the front-end once the user login and is able to refresh the id token and access token using the refresh token if either are not valid anymore.
The front-end SPA works independent and relies on the localStorage entries setup by aws-amplify
. Once the tokens are invalid it's actually triggering the AWS call to refresh the token but it's not working.
I'm not sure if it's a problem with aws-amplify
itself - could as well be a bug in Cognito - but the fact is that the refresh works when the back-end triggers it using aws-sdk
.
I had a similar issue before. I use the currentSession()
method instead and it refresh correctly the token.
/**
* Return the Cognito User Pool token of the authenticated user.
*/
export function currentUserToken() {
return Auth.currentSession().then((session) => {
return session.idToken.jwtToken;
});
}
Thanks @Hugodby will give it a try :+1:
So figured out what was happening. It seems to be a bug either in this library or with Cognito, haven't figured out yet.
Our users are being brought over using the User Migration Lambda, which means whenever they login they are migrated across. So far, so good. It also means that we need to use the USER_PASSWORD_AUTH
authentication flow type instead of the default USER_SRP_AUTH
.
And this is the problem: whenever we use the USER_PASSWORD_AUTH
authentication flow type I get a HTTP 400
with a NotAuthorized exception.
I tested it by issuing a request with USER_SRP_AUTH
in the authentication flow type and I got a successful token every time.
It seems that tokens issued by the USER_PASSWORD_AUTH
are not being validated correctly in Cognito - it seems to be a problem in the platform, not in this library.
Is it a authentication level issue... can you adjust the authentication to aws_iam instead of Logged In Cognito User, then adjust your own code to reflect the authentication changes... ? i.e. Instead of allowing access to the resources based on individual signed in Cognito Users, allow the access to the entire aws_iam account, then assign Logged In User Pool access to the aws_iam accounts resources.
@michaelcuneo I'm not sure I understand what you mean. Are you talking about this? https://docs.aws.amazon.com/cognito/latest/developerguide/resource-permissions.html
I can confirm that this is not an issue with the library. Our user pool got misconfigured generating false negatives. Happy to close this!
Hi @tarciosaraiva, if it won't divulge any secrets or security issues, would you mind explaining what the misconfiguration is/was? I am running into the exact problem, i.e. migrated user accounts and using USER_PASSWORD_AUTH to facilitate the migration trigger.
Hi @tcchau our configuration is setup using terraform and I was fiddling with thr "Advanced Security" features in Cognito - among other things - that caused something in their engine to generate tokens with a certain signature that could not be verified using the USER_PASSWORD_AUTH method for some reason.
I've since recreated the user pool and all is well.
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.
Do you want to request a feature or report a bug? Report a bug.
What is the current behavior? User logs in using
USER_PASSWORD_AUTH
authentication flow type, stays on the app for 1 hour. Moves on to another page on the app, aPOST
request to Cognito is issued to refresh the token and the response is HTTP 400.The app invokes
Auth.currentAuthenticatedUser()
whenever moving between pages.Request
Request POST data
Response
What is the expected behavior? Expected the session to be successfully refreshed.
Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions? The version of Amplify I'm using is
@aws-amplify/auth 1.0.0
. All browsers.