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

Issue #367: Refresh token expiration fix #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/Flows/OAuth2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ open class OAuth2: OAuth2Base {
callback(json, nil)
}
catch let error {
// Fixes [Issue #367](https://github.com/p2/OAuth2/issues/367)
// Refresh token needs to be cleared out upon error, otherwise re-authorizing will not ocurr because the library thinks it has a valid refresh token and tries to fetch a new access token with an expired refresh token.
self.clientConfig.refreshToken = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would clear the refresh token on any error, also e.g. when the server is temporarily unavailable (OAuth2Error.temporarilyUnavailable). I don't think this is desirable. The right way would be to check if the error is the invalid_grant error (which is thrown as OAuth2Error.invalidGrant) and delete the refresh token only in that case.

self.logger?.debug("OAuth2", msg: "Error refreshing access token: \(error)")
callback(nil, error.asOAuth2Error)
}
Expand Down