Skip to content

Retain refresh token expiry on refreshing #360

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

Merged
merged 13 commits into from
May 17, 2022

Conversation

chrisirhc
Copy link
Contributor

@chrisirhc chrisirhc commented Apr 20, 2022

Right now, on refreshing tokens, the refresh token becomes treated as never expiring since the refresh_expires* properties are not persisted on refresh.

@sqrrrl
Copy link
Member

sqrrrl commented Apr 25, 2022

Appreciate the fix as it does seem like there's a bug there. There's a few issues per comments.

Suggest approach this a little differently:

  1. instead of saving granted_time, which is ambiguous with two different expiries in play, convert expires_in/refresh_expires_in to expires_at/refresh_expires_at in parse_token. This way we have always have both fields as absolute times.
  2. Update the expiration checks to first check for the new fields, fall back on the old checks for existing tokens/migration.
  3. Update the refresh method to make sure expires_at/refresh_expires_at are propagated to the new token if omitted in the server response. Can also handle migration here too and convert refresh_expires_in to refresh_expires_at.

That's a bit more work, but eventually should allow the expiration checks to be simplified later on after users have a chance to migrate.

The alternative would be to update parse_token to record a new refresh_token_granted_at timestamp if a refresh token is present, then propagate that + refresh_expires_in as discussed + update the refresh expiry checks appropriately.

@chrisirhc
Copy link
Contributor Author

Updated PR based on comments.
Please take a look.

@chrisirhc
Copy link
Contributor Author

Did another pass and addressed the changes as well as added tests.

@sqrrrl sqrrrl merged commit 058dfcd into googleworkspace:master May 17, 2022
@chrisirhc chrisirhc deleted the fix-refresh-token-expires branch May 18, 2022 01:56
sqrrrl added a commit that referenced this pull request Aug 2, 2022
* fix refresh token expiry lost during refresh

* add failing test

* revert previous changes to go with a different approach

* stab at expires at variables

* fix test and typo

* fix typo

* clean up code for easier review, minimize changes, follow previus patterns

* add missing var

* fix canRefresh logic

* add setExpiresAt tests

* remove extra comment

* add tests and fix typo in logic

Co-authored-by: Steve Bazyl <sbazyl@google.com>
sqrrrl added a commit that referenced this pull request Aug 2, 2022
* fix refresh token expiry lost during refresh

* add failing test

* revert previous changes to go with a different approach

* stab at expires at variables

* fix test and typo

* fix typo

* clean up code for easier review, minimize changes, follow previus patterns

* add missing var

* fix canRefresh logic

* add setExpiresAt tests

* remove extra comment

* add tests and fix typo in logic

Co-authored-by: Steve Bazyl <sbazyl@google.com>
sqrrrl added a commit that referenced this pull request Aug 2, 2022
* fix refresh token expiry lost during refresh

* add failing test

* revert previous changes to go with a different approach

* stab at expires at variables

* fix test and typo

* fix typo

* clean up code for easier review, minimize changes, follow previus patterns

* add missing var

* fix canRefresh logic

* add setExpiresAt tests

* remove extra comment

* add tests and fix typo in logic

Co-authored-by: Steve Bazyl <sbazyl@google.com>
sqrrrl added a commit that referenced this pull request Aug 2, 2022
* fix refresh token expiry lost during refresh

* add failing test

* revert previous changes to go with a different approach

* stab at expires at variables

* fix test and typo

* fix typo

* clean up code for easier review, minimize changes, follow previus patterns

* add missing var

* fix canRefresh logic

* add setExpiresAt tests

* remove extra comment

* add tests and fix typo in logic

Co-authored-by: Steve Bazyl <sbazyl@google.com>
sqrrrl added a commit that referenced this pull request Aug 2, 2022
* fix refresh token expiry lost during refresh

* add failing test

* revert previous changes to go with a different approach

* stab at expires at variables

* fix test and typo

* fix typo

* clean up code for easier review, minimize changes, follow previus patterns

* add missing var

* fix canRefresh logic

* add setExpiresAt tests

* remove extra comment

* add tests and fix typo in logic

Co-authored-by: Steve Bazyl <sbazyl@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants