From 21f0dc051f90b31516c48ece0602bf0c2185d842 Mon Sep 17 00:00:00 2001 From: Mark James Date: Sat, 9 Aug 2025 20:04:19 +1000 Subject: [PATCH 1/4] Add refresh_access_token & set_access_token_from_hash methods. --- lib/omniauth/strategies/oauth2.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/omniauth/strategies/oauth2.rb b/lib/omniauth/strategies/oauth2.rb index 1588926..f0912ee 100644 --- a/lib/omniauth/strategies/oauth2.rb +++ b/lib/omniauth/strategies/oauth2.rb @@ -89,7 +89,7 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"])) else self.access_token = build_access_token - self.access_token = access_token.refresh! if access_token.expired? + refresh_access_token if access_token.expired? super end rescue ::OAuth2::Error, CallbackError => e @@ -100,6 +100,14 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi fail!(:failed_to_connect, e) end + def set_access_token_from_hash(hash) + self.access_token = ::OAuth2::AccessToken.from_hash(client, hash) + end + + def refresh_access_token + self.access_token = access_token&.refresh(token_params.to_hash(symbolize_keys: true), deep_symbolize(options.auth_token_params)) + end + protected def pkce_authorize_params From 2336a45a44f221b0151b5e695a4149f529d0fc3b Mon Sep 17 00:00:00 2001 From: Mark James Date: Tue, 19 Aug 2025 02:17:11 +1000 Subject: [PATCH 2/4] stringify keys of refresh params to match the added id & secret --- lib/omniauth/strategies/oauth2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/omniauth/strategies/oauth2.rb b/lib/omniauth/strategies/oauth2.rb index f0912ee..6c083ae 100644 --- a/lib/omniauth/strategies/oauth2.rb +++ b/lib/omniauth/strategies/oauth2.rb @@ -105,7 +105,7 @@ def set_access_token_from_hash(hash) end def refresh_access_token - self.access_token = access_token&.refresh(token_params.to_hash(symbolize_keys: true), deep_symbolize(options.auth_token_params)) + self.access_token = access_token&.refresh(token_params.to_hash(stringify_keys: true), deep_symbolize(options.auth_token_params)) end protected From fd8b6897cbeb75807f50a8e3549cd1c3dd7317b2 Mon Sep 17 00:00:00 2001 From: Mark James Date: Mon, 8 Sep 2025 16:44:48 +1000 Subject: [PATCH 3/4] Factor out symbolized_auth_token_params, and add to set_access_token_from_hash hash --- lib/omniauth/strategies/oauth2.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/omniauth/strategies/oauth2.rb b/lib/omniauth/strategies/oauth2.rb index 6c083ae..d27b9fe 100644 --- a/lib/omniauth/strategies/oauth2.rb +++ b/lib/omniauth/strategies/oauth2.rb @@ -100,12 +100,16 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi fail!(:failed_to_connect, e) end + def symbolized_auth_token_params + deep_symbolize(options.auth_token_params) + end + def set_access_token_from_hash(hash) - self.access_token = ::OAuth2::AccessToken.from_hash(client, hash) + self.access_token = ::OAuth2::AccessToken.from_hash(client, hash.update(symbolized_auth_token_params) end def refresh_access_token - self.access_token = access_token&.refresh(token_params.to_hash(stringify_keys: true), deep_symbolize(options.auth_token_params)) + self.access_token = access_token&.refresh(token_params.to_hash(stringify_keys: true), symbolized_auth_token_params) end protected @@ -131,7 +135,7 @@ def pkce_token_params def build_access_token verifier = request.params["code"] - client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params)) + client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true)), symbolized_auth_token_params) end def deep_symbolize(options) From 77bd3f45083e44b81891f2011d9669c0943abfd4 Mon Sep 17 00:00:00 2001 From: Mark James Date: Tue, 9 Sep 2025 14:32:33 +1000 Subject: [PATCH 4/4] Fix syntax error --- lib/omniauth/strategies/oauth2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/omniauth/strategies/oauth2.rb b/lib/omniauth/strategies/oauth2.rb index d27b9fe..90e8f69 100644 --- a/lib/omniauth/strategies/oauth2.rb +++ b/lib/omniauth/strategies/oauth2.rb @@ -105,7 +105,7 @@ def symbolized_auth_token_params end def set_access_token_from_hash(hash) - self.access_token = ::OAuth2::AccessToken.from_hash(client, hash.update(symbolized_auth_token_params) + self.access_token = ::OAuth2::AccessToken.from_hash(client, hash.update(symbolized_auth_token_params)) end def refresh_access_token