-
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
Storage.put uses expired token #14174
Comments
Hello, @makeitraina and thanks for opening this issue. This issue should be resolved in v6 of Amplify (current major version) and want to see if you have the ability to upgrade to that first before delving into the v5 side of things. We have migration guides available for Storage and other categories as well. Let us know if this works and if you can upgrade to v6! |
I would love to upgrade, but its such a big undertaking. We rely on Auth as well and there is a lot of logic that would need to be switched over. Separately, I spent a lot of time debugging the code and I think I found the problem. In put why dont we call _ensureCredentials like we do for all the other s3 methods? |
@makeitraina, understandable that the upgrade from v5 to v6 requires a bit of heavy lifting with all the changes to API's. It does appear however that you're quite a few versions behind the latest v5 (currently the latest is 5.3.27), and there were some changes and fixes made in some of those more recent version. Can you upgrade to the latest v5 and see if the behavior is resolved? |
Yup, after I found the issue, I did try an upgrade but the problem still happened. I think the fix is really just to add that ensure credentials call in the Referring to this comment |
Here is a pull request: #14176 |
Hi @makeitraina Thanks for this PR! Just to help us understand the scope of this issue, do you see the same issue if you set the Storage.put(key, file, {
level: 'protected',
progressCallback,
contentType: file.type,
resumable: true,
}); |
@AllanZhengYP yes, same issue happens there as well. |
Hi @makeitraina I created a minimal reproduction on the version The line you pointed out in the PR does not seem to be the root cause. The Can you also share the similar screenshot of network tab at the upload failure as well as the stack trace? |
I do see your point about that Storage.put can last a long time so my solution is not complete in that sense. But i think there is still a problem here. In the same code you pointed to there is a check for if config.credentials is already set.
So its using the config.credentials that are passed in from the param. If you go up the stack to where AWSS3ProviderManagedUpload is initialized you can see the opts come from the existing config which has the previous credentials But based on the line of code I just pointed to you can see the problem right? If credentials are set in the config of the AWSS3Prodvider object then the callback to resolve credentials will never gets called. |
@makeitraina, are you able to share a screenshot of network tab when you're making the |
Hey sorry @cwomack I needed an unblock sooner so I've gone with my existing solution in project and so reproducing the problem above is not straightforward and would require a lot more setup on my end. Just not enough time for me to go too deep and debug. As you know I have to wait an hour to debug this and record it accordingly. Im in agreement with @AllanZhengYP that my solution isn't perfect because of the need for Put to be a potentially long running request, so my PR can be closed. Also, Im not doing Amplify.configure(), instead Im doing Storage.configure(). It looks like:
I still think my reply in the comment here holds, but I see this might be a more involved fix and given the state of things I understand if you want to close this issue. |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Storage
Amplify Version
v5
Amplify Categories
storage, auth
Backend
Other
Environment information
Describe the bug
When uploading files to S3 using Storage.put I will receive an error
ExpiredToken: The provided token has expired.
This only happens if I've left my window open for > 1hr. When I first start the app and upload everything works correctly.Expected behavior
Uploads should still work after an hour of inactivity without hard refreshing/restarting the app.
The token should be refreshed (which it looks like is happening from the debug logs) and upload should use the non expired tokens.
Reproduction steps
Code Snippet
Log output
No response
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: