Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

expiry test for tokens running off local time, not auth time #189

Open
coderdecoder opened this issue Jan 14, 2022 · 1 comment
Open

expiry test for tokens running off local time, not auth time #189

coderdecoder opened this issue Jan 14, 2022 · 1 comment

Comments

@coderdecoder
Copy link

If you look in your check expiry function you'll see that you're using time.time() to get the local server time, then evaluating that against the expiry. This is not correct as if you're running the webserver in a different timezone the times will no longer line up.

To correct this I think what is needed is to log time.time() when the request is made internally to create an offset and evaluate based off this.

@coderdecoder
Copy link
Author

Here is my local solution, I'm not sure where you'd like to store the value or I'd implement it myself and push it. When I get/refresh my tokens I log the local time.

    session['cognito_token_time'] = time.time()

Use test mode and apply the offeset if any:

#if token is expiring soon refresh and re-decode-verify
expiring_in = verified_claims['exp'] - time.time() - (verified_claims['auth_time'] - session['cognito_token_time'])
if(expiring_in < 0):
    raise Exception('Token is expired')

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant