-
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
fix(@aws-amplify/core): Support clock skew #4844
fix(@aws-amplify/core): Support clock skew #4844
Conversation
…hirata/amplify-js into 3567-clock-skew
Codecov Report
@@ Coverage Diff @@
## master #4844 +/- ##
==========================================
- Coverage 76.28% 76.28% -0.01%
==========================================
Files 174 175 +1
Lines 9644 9652 +8
Branches 1977 1978 +1
==========================================
+ Hits 7357 7363 +6
- Misses 2142 2144 +2
Partials 145 145
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Thanks @ericclemmons! This looks promising.
Can you confirm that: should actually be: It'd be great with an example on how to use this in a normal use case for example in a React component.
Is there a particular reason for not making it default now? For developers using Amplify, realizing that this is in fact a problem affecting their app/platform, that typically starts with getting random user reports with 403 errors, to realizing the exact reason for the error seems long and painful. This should at least be documented. |
@houmark Whoops, I mistyped the sample above. It now reads: import { DateUtils } from "@aws-amplify/core" You're exactly right: now that we have the API in place, we'll be working on handling this automatically. The level of effort is higher than this PR, so we wanted to get it in customers' hands sooner. I shared my notes on how I've been reproducing the clock skew errors here: The next steps are to get I'll report back if I find new ways of leveraging this API on your own. Until then, a couple customers noted their solutions here:
Thanks @houmark for staying on top of this & working with me on it! |
Thanks @ericclemmons! Sorry for my ignorance, but I'm still a bit confused about how to use this particular fix in for example a React component. I have a component that is doing an unAuth'ed GraphQL query, so it's using authMode Do you know when you'll be releasing |
@houmark I have just tested amplify 2.2.4 with DateUtils.setClockOffset(CLOCK_OFFSET) at the start of our application and it looks good. |
@dorsegal What method are you using for computing the |
|
@dorsegal Ah, thanks! We were testing out that method, but have to dig more into internals to support the "logged out" scenario: where a user can't even sign in due to clock skew. |
* fix(@aws-amplify/core): AWS.config.systemClockOffset for signing requests * Add Util/Date to support new Date() with clock offset * Add tests for Utils.Date * Signer users Util.Date * Remove unused "date" for mocking * Rename Date to DateUtils to allow "import { DateUtils }" * Reference DateUtils directly vs. Utils.DateUtils * Move DateUtils.test.ts so that core can build * Add annotation to clockOffset for documentation & intellisense * Fix test path * Improve JSDoc Co-authored-by: Thiago Hirata <hirata@devcase.com.br> Co-authored-by: Sam Martinez <sammartinez19@gmail.com>
@ericclemmons @dorsegal @houmark To fix clock skew for non-logged in users using DateUtils.setClockOffset, we can do this. It worked for both logged-in and non-logged-in users.
In aws-sdk.js, there are functions to handle clockSkew: Automate Clock Skew Fix AttemptFurthermore, In aws-sdk.js, there is CognitoIdentityCredentials class that takes ConfigurationOptions as argument. There is this option Using DateUtils, I tested locally by changing js files(Credentials.js in @aws-amplify/auth) in node_modules and it seemed to work.
How can I link amplify library locally and test with my changes?
During
in my project folder, I ran
|
@ericclemmons |
I also have the same problem. Auth.currentUserCredentials() can't return cognito.config.systemClockOffset, return accessKeyId, sessionToken, secretAccessKey, identityId, authenticated properties :/ |
This pull request 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 |
Issue #, if available: Fixes #3567, fixes #4556 with help from @thiagohirata in #4251
Description of changes:
When reviewing @thiagohirata's PR (#4251) with the team, we learned that the
AWS
export will be removed in the near future.So that
Signer.ts
honors clock skew, this PR introducesDateUtils
for setting clock skew by embeddinggetDate()
fromaws-sdk
Users will be able to adjust this value in a backwards-compatible way via:
Internally,
Signer.ts
replaces calls tonew Date()
withDateUtils.getDateWithClockOffset()
.Type annotations:
This creates an opening for Amplify to automatically adjust clock-skew on users' behalf in the future.
Closes #4251
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.