From 01e8a9b3da68d655025dc5a03baa80603cca2264 Mon Sep 17 00:00:00 2001 From: josephquigley Date: Wed, 4 Oct 2023 13:41:58 -0400 Subject: [PATCH] Fixes [Issue #367](https://github.com/p2/OAuth2/issues/367) where expired refresh tokens were not cleared, preventing re-authorization. --- Sources/Flows/OAuth2.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Flows/OAuth2.swift b/Sources/Flows/OAuth2.swift index 5c69667..60da15f 100644 --- a/Sources/Flows/OAuth2.swift +++ b/Sources/Flows/OAuth2.swift @@ -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 self.logger?.debug("OAuth2", msg: "Error refreshing access token: \(error)") callback(nil, error.asOAuth2Error) }