Skip to content

Commit 21f0dc0

Browse files
committed
Add refresh_access_token & set_access_token_from_hash methods.
1 parent c830138 commit 21f0dc0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/omniauth/strategies/oauth2.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi
8989
fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
9090
else
9191
self.access_token = build_access_token
92-
self.access_token = access_token.refresh! if access_token.expired?
92+
refresh_access_token if access_token.expired?
9393
super
9494
end
9595
rescue ::OAuth2::Error, CallbackError => e
@@ -100,6 +100,14 @@ def callback_phase # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexi
100100
fail!(:failed_to_connect, e)
101101
end
102102

103+
def set_access_token_from_hash(hash)
104+
self.access_token = ::OAuth2::AccessToken.from_hash(client, hash)
105+
end
106+
107+
def refresh_access_token
108+
self.access_token = access_token&.refresh(token_params.to_hash(symbolize_keys: true), deep_symbolize(options.auth_token_params))
109+
end
110+
103111
protected
104112

105113
def pkce_authorize_params

0 commit comments

Comments
 (0)