omniauth-facebook2 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c051fcad79b58c9fd1988af188abaa207b500e3cf6380f005ff2541709419d3
4
- data.tar.gz: f3a352c67dec65e0332fbafd805f3e508675ee5a5fc71cde0e6e8c055f114b71
3
+ metadata.gz: 8be4fa997d52fac1a5aeb94f7c263ea302c73aad21ae1ca781894b9ba334af36
4
+ data.tar.gz: 26d1801e8ced6643562da38aaf2ea8da7af8753236d837c7c26884deec1556ca
5
5
  SHA512:
6
- metadata.gz: 5433ff4b75e0bb8335e975b5f973d111cdc645c2de8cff6cc82527deae5eee643eaf5f0b57ed49a24941375533f37c44791fbdf9ded21e3d8556e041c08bae41
7
- data.tar.gz: 331e183495646573db070811ac4ea5ff4c53dec6db57956d75fa5daf17b1d9f01416986fbec5287de861e1be14027b2f4b7673741cb30feff23de875581548e8
6
+ metadata.gz: '0924c4c2d93d3cac3359b0c1ca7a2a8a953a6193bd017144d1aaf049f534773441635e37292df45eaf5dbe3dd733915af117035d79f6a8c19e2738f493a1322b'
7
+ data.tar.gz: d101c589578e6201bf7b4c8d8b6064f8de43fdff3d81b0b503af72cc63d9b3be5711d32f05199090e1c08686cee0fdde73187d362d446f8f5fea906a6c84a38a
data/README.md CHANGED
@@ -27,7 +27,8 @@ Configure OmniAuth in your Rack/Rails app:
27
27
  Rails.application.config.middleware.use OmniAuth::Builder do
28
28
  provider :facebook2,
29
29
  ENV.fetch('FACEBOOK_APP_ID'),
30
- ENV.fetch('FACEBOOK_APP_SECRET')
30
+ ENV.fetch('FACEBOOK_APP_SECRET'),
31
+ api_version: 'v26.0' # optional; default is v25.0
31
32
  end
32
33
  ```
33
34
 
@@ -52,6 +53,7 @@ end
52
53
  Supported request/provider options include:
53
54
 
54
55
  - `scope` (default: `email`)
56
+ - `api_version` (default: `v25.0`)
55
57
  - `display`
56
58
  - `auth_type` (example: `rerequest`)
57
59
  - `config_id` (Facebook Login for Business)
@@ -62,6 +64,19 @@ Supported request/provider options include:
62
64
  - `secure_image_url` (default: `true`)
63
65
  - `callback_url` / `callback_path`
64
66
 
67
+ If you need full endpoint control, `client_options` still works and takes precedence over `api_version`:
68
+
69
+ ```ruby
70
+ provider :facebook2,
71
+ ENV.fetch('FACEBOOK_APP_ID'),
72
+ ENV.fetch('FACEBOOK_APP_SECRET'),
73
+ client_options: {
74
+ site: 'https://graph.facebook.com/v26.0',
75
+ authorize_url: 'https://www.facebook.com/v26.0/dialog/oauth',
76
+ token_url: 'oauth/access_token'
77
+ }
78
+ ```
79
+
65
80
  ## Auth Hash
66
81
 
67
82
  Example payload from `request.env['omniauth.auth']` (captured from a real smoke run):
@@ -111,11 +126,11 @@ RAILS_VERSION='~> 8.1.0' bundle exec rake test_rails_integration
111
126
 
112
127
  ## Endpoints
113
128
 
114
- Default endpoints target Facebook Graph API `v25.0`:
129
+ Default endpoints target Facebook Graph API `v25.0` (or `vX.Y` set via `api_version`):
115
130
 
116
- - Authorize: `https://www.facebook.com/v25.0/dialog/oauth`
117
- - Token: `https://graph.facebook.com/v25.0/oauth/access_token`
118
- - User info: `https://graph.facebook.com/v25.0/me`
131
+ - Authorize: `https://www.facebook.com/vX.Y/dialog/oauth`
132
+ - Token: `https://graph.facebook.com/vX.Y/oauth/access_token`
133
+ - User info: `https://graph.facebook.com/vX.Y/me`
119
134
 
120
135
  ## Test Structure
121
136
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Facebook2
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -14,9 +14,11 @@ module OmniAuth
14
14
  DEFAULT_SCOPE = 'email'
15
15
  DEFAULT_FACEBOOK_API_VERSION = 'v25.0'
16
16
  DEFAULT_INFO_FIELDS = 'name,email'
17
+ DEFAULT_TOKEN_URL = 'oauth/access_token'
17
18
 
18
19
  option :name, 'facebook2'
19
20
  option :scope, DEFAULT_SCOPE
21
+ option :api_version, DEFAULT_FACEBOOK_API_VERSION
20
22
  option :authorize_options, %i[scope display auth_type config_id redirect_uri]
21
23
  option :secure_image_url, true
22
24
  option :appsecret_proof, true
@@ -25,7 +27,7 @@ module OmniAuth
25
27
  option :client_options,
26
28
  site: "https://graph.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}",
27
29
  authorize_url: "https://www.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}/dialog/oauth",
28
- token_url: 'oauth/access_token',
30
+ token_url: DEFAULT_TOKEN_URL,
29
31
  connection_opts: {
30
32
  headers: {
31
33
  user_agent: 'icoretech-omniauth-facebook2 gem',
@@ -98,6 +100,14 @@ module OmniAuth
98
100
  fail!(:unknown_signature_algorithm, e)
99
101
  end
100
102
 
103
+ def client
104
+ @client ||= ::OAuth2::Client.new(
105
+ options.client_id,
106
+ options.client_secret,
107
+ deep_symbolize(normalized_client_options)
108
+ )
109
+ end
110
+
101
111
  def callback_url
102
112
  return '' if options.authorization_code_from_signed_request_in_cookie
103
113
 
@@ -201,6 +211,38 @@ module OmniAuth
201
211
  token_params['scope'] || (access_token['scope'] if access_token.respond_to?(:[]))
202
212
  end
203
213
 
214
+ def normalized_client_options
215
+ client_options = options.client_options.to_h.transform_keys(&:to_sym)
216
+ version = options[:api_version]
217
+ return client_options if blank?(version)
218
+
219
+ current_site = client_options[:site]
220
+ current_authorize_url = client_options[:authorize_url]
221
+ current_token_url = client_options[:token_url]
222
+ default_site = graph_site_for(DEFAULT_FACEBOOK_API_VERSION)
223
+ default_authorize_url = authorize_url_for(DEFAULT_FACEBOOK_API_VERSION)
224
+
225
+ client_options[:site] = graph_site_for(version) if default_endpoint?(current_site, default_site)
226
+ if default_endpoint?(current_authorize_url, default_authorize_url)
227
+ client_options[:authorize_url] = authorize_url_for(version)
228
+ end
229
+ client_options[:token_url] = DEFAULT_TOKEN_URL if blank?(current_token_url)
230
+
231
+ client_options
232
+ end
233
+
234
+ def graph_site_for(version)
235
+ "https://graph.facebook.com/#{version}"
236
+ end
237
+
238
+ def authorize_url_for(version)
239
+ "https://www.facebook.com/#{version}/dialog/oauth"
240
+ end
241
+
242
+ def default_endpoint?(value, default_value)
243
+ blank?(value) || value == default_value
244
+ end
245
+
204
246
  def blank?(value)
205
247
  value.nil? || (value.respond_to?(:empty?) && value.empty?)
206
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-facebook2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Poli