-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Device metadata is being deleted when using default storage as session storage #14135
Comments
Hello, @2-Dpot and thanks for creating this issue. Are you able to share more details about the custom auth flow that you've set up by sharing some of the frontend code where you're calling |
Also, are you using the storing mechanism that Amplify uses out of the box (which would be localStorage), or is the deviceMetaData being stored in a custom rolled Session Storage? |
Here is a small sample of my code , hopefully it explains the issue . //app-config.ts awsconfig = { Amplify.configure(awsconfig); cognitoUserPoolsTokenProvider.setKeyValueStorage(sessionStorage); //Login.ts //If device key exist in cookie ? Do the below |
As you can see from the above code In MFA page when correct custom challenge is answered , I notice device details (deviceKey, dev ceGroupKey, randomPasswordKey) When Refresh token is called post this in the payload the deviceKey is passed by amplify and is successful. But in the 'DONE' condition as seen in login.component.ts NOTE: All flows work completely fine if I'm using cookie as the default storage. As when we do that post logout , device details are not removed from the cookie , so in the next login refreshToken works completely fine as deviceKey is passed in its payload. |
@2-Dpot, thanks for the reply and additional context. If you're using You could potentially lower the TTL's for the auth tokens to the lowest value possible to try to help with all this as another consideration. Can you possibly clarify how you're using the device data a little more? Trying to see if there's a possibility that this is a feature request for more fine grained control of the the auth tokens/metadata based on the use case. |
Giving more context inthe code which we use to handle device metadata. //mfaPage.ts //After some time calling refresh token like below //The payload of the above cognito call has a refresh token and a deviceKey which I assume amplify takes care of by picking it from the session storage. But in my other flow the same refresh token api doesn't pass the deviceKey in the payload only refreshToken key exists as a result the call fails with invalid refresh token. NOTE : I had to type all these from a phone due to a limitation so excuse my my spacing and code details. |
Hi @2-Dpot, thanks for the additional information. I have a few more questions to try and help us get to the bottom of this.
Also, please keep in mind that when using session storage as the storage mechanism both device metadata and tokens will be lost when the tab is closed. Is this the intended behavior? |
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
No response
Backend
Other
Environment information
Describe the bug
I have an angular application that uses CUSTOM_AUTH flow for authentication,
This custom auth flow redirects the end user to a custom MFA page where the end users completes the challenge by entering an OTP.
If the OTP is correct I use the amplify rememberDevice method to track the device.
At this point in time if fetchAuthSession({force refresh: true }) is called it refreshes correctly.
The issue happens if the same user relogs in the tracked device , then we don't redirect them to the custom challenge flow , we directly log them in with the correct password.
Now this time the device meta data don't stay in the session storage ,
Now when the fetchAuthSession({force refresh: true }) fails with invalid refresh token error.
(Most likely because device key is not passed as payload in the refresh token api call.)
In v5 version of amplify we used to do something similar to
cognitoUser.getCachedDeviceKeyAndPassword()
Before calling the refresh token and it used to work .
Expected behavior
Refresh token call should work.
Amplify should handle the places where device meta data needs to be passed.
Reproduction steps
Code Snippet
// Put your code below this line.
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
The text was updated successfully, but these errors were encountered: