Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Allow configuring country via options
Browse files Browse the repository at this point in the history
This allows the OAuth2 client provided by the strategy to be used for
refreshing the token
  • Loading branch information
jaredmoody committed May 23, 2017
1 parent 1d6238c commit bb108cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth-sageone/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module SageOne
VERSION = '0.2.0'.freeze
VERSION = '0.3.0'.freeze
end
end
16 changes: 7 additions & 9 deletions lib/omniauth/strategies/sage_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class SageOne < OmniAuth::Strategies::OAuth2
end

# SageOne has different token endpoints for each available country. The country is returned in
# the authorization callback. Configure the OAuth client to use that information.
# the authorization callback. Configure the OAuth client to use that information by
# customizing the client options
def client
::OAuth2::Client.new(options.client_id, options.client_secret, client_options)
end
Expand All @@ -56,17 +57,14 @@ def build_access_token
end

def country
request[:country].try(:downcase)
request.env ? request[:country].try(:downcase) : options.client_options[:country]
end

# Override client_options[:token_url] using the country from ether the request or the
# provided country option
def client_options
hash = if country
{ token_url: TOKEN_URLS[country] }.merge(options.client_options)
else
options.client_options
end

deep_symbolize(hash)
options.client_options[:token_url] = TOKEN_URLS[country] if country
deep_symbolize(options.client_options)
end
end
end
Expand Down

0 comments on commit bb108cc

Please sign in to comment.