Skip to content
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 a UTC Time conversion bug #223

Merged
merged 1 commit into from
Feb 9, 2023
Merged

Fix a UTC Time conversion bug #223

merged 1 commit into from
Feb 9, 2023

Conversation

PhonicCanine
Copy link
Contributor

The UTC time offset is currently converted straight to a DateTime in the computer's local timezone. It is then passed into the CognitoUserSession constructor, where it is converted to a universal time.
If you're in a timezone +'ve of UTC this means that IsValid on the CognitoUserSession will always return false, which breaks a number of other methods in the User Manager (anything that checks for authentication).

Issue #, if available:
On Line 168 of CognitoUserManager this line of code exists:
user.SessionTokens = new CognitoUserSession(idToken, accessToken, refreshToken, result.Properties.IssuedUtc.Value.DateTime, result.Properties.ExpiresUtc.Value.DateTime);

This writes the UTC time into a local time, and then the CognitoUserSession constructer makes that local time a UTC time. This means that the time written to the CognitoUserSession for token expiry is incorrect, and if you're in a positive timezone, it means IsValid won't return true.

Description of changes:

Fixed this time conversion bug by changing .Value.DateTime to .Value.UtcDateTime.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The UTC time offset is currently converted straight to a DateTime in the computer's local timezone. It is then passed into the CognitoUserSession constructor, where it is converted to a universal time.
If you're in a timezone +'ve of UTC this means that IsValid on the CognitoUserSession will always return false, which breaks a number of other methods in the User Manager (anything that checks for authentication).
@ashishdhingra ashishdhingra added the bug This issue is a bug. label Oct 11, 2022
@normj normj merged commit bc64083 into aws:master Feb 9, 2023
@normj
Copy link
Member

normj commented Feb 10, 2023

PR has been released as part of version 3.0.1. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants