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

preserve old refresh token if new token does not contain refresh token #434

Merged
merged 1 commit into from
Jun 30, 2024

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jun 29, 2023

Fixes #431

@huzaifahj
Copy link

@jonathansamines Can this be merged?

@mindesik
Copy link

@jonathansamines jonathansamines merged commit 176ef7b into lelylan:master Jun 30, 2024
@jonathansamines
Copy link
Collaborator

Thanks for the contribution @Uzlopak

@jonathansamines
Copy link
Collaborator

Changes released in v5.1.0

@ptesny
Copy link

ptesny commented Dec 31, 2024

The fix is is not working. The refresh_token is being overwritten by undefined. Not sure how you tested it?

I get the 'refresh_token' set to undefined in lieu of the refresh token.

https://github.com/lelylan/simple-oauth2/blob/master/lib/access-token.js#L42-L52

The culprit is line https://github.com/lelylan/simple-oauth2/blob/master/lib/access-token.js#L52
it should be:

response.refresh_token = this.token.refresh_token;

in lieu of:

response.refresh_token = this.refresh_token

So the corrected code would like this:

if (response[REFRESH_TOKEN_PROPERTY_NAME] === undefined) {
      response.refresh_token = this.token.refresh_token;
    }

Due to this bug the latest version of the library broke my code:

const merged_accessToken = { ...token.token, ...refreshedToken.token };

as the token.token.refresh_token was being replaced by undefined from refreshedToken.token.refresh_token

@Uzlopak Uzlopak deleted the preserve-refresh-token branch December 31, 2024 10:02
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Dec 31, 2024

@ptesny oh! You are right. I am just testing if the key exists but not if the key is not undefined

Can you provide a PR?

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.

Cannot refresh a second time after the first refresh
5 participants