Skip to content

Commit 36f8c39

Browse files
authored
Bump Facebook Graph API to v5.0 (#366)
* Add DEFAULT_FACEBOOK_API_VERSION constant
1 parent 853dce6 commit 36f8c39

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 9.0.0 (2021-10-25)
2+
3+
Changes:
4+
5+
- bumped version of FB Graph API to v5.0
6+
17
## 8.0.0 (2020-10-20)
28

39
Changes:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858

5959
### API Version
6060

61-
OmniAuth Facebook uses versioned API endpoints by default (current v4.0). You can configure a different version via `client_options` hash passed to `provider`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v7.0 (assuming that exists):
61+
OmniAuth Facebook uses versioned API endpoints by default (current v5.0). You can configure a different version via `client_options` hash passed to `provider`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v7.0 (assuming that exists):
6262

6363
```ruby
6464
use OmniAuth::Builder do

lib/omniauth/facebook/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module OmniAuth
22
module Facebook
3-
VERSION = '8.0.0'
3+
VERSION = '9.0.0'
44
end
55
end

lib/omniauth/strategies/facebook.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ class Facebook < OmniAuth::Strategies::OAuth2
1010
class NoAuthorizationCodeError < StandardError; end
1111

1212
DEFAULT_SCOPE = 'email'
13+
DEFAULT_FACEBOOK_API_VERSION = 'v5.0'.freeze
1314

1415
option :client_options, {
15-
site: 'https://graph.facebook.com/v4.0',
16-
authorize_url: "https://www.facebook.com/v4.0/dialog/oauth",
16+
site: "https://graph.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}",
17+
authorize_url: "https://www.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}/dialog/oauth",
1718
token_url: 'oauth/access_token'
1819
}
1920

test/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def setup
4242
@client_id = '123'
4343
@client_secret = '53cr3tz'
4444
@options = {}
45+
46+
@facebook_api_version = OmniAuth::Strategies::Facebook::DEFAULT_FACEBOOK_API_VERSION
4547
end
4648

4749
def strategy

test/strategy_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class StrategyTest < StrategyTestCase
99

1010
class ClientTest < StrategyTestCase
1111
test 'has correct Facebook site' do
12-
assert_equal 'https://graph.facebook.com/v4.0', strategy.client.site
12+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}", strategy.client.site
1313
end
1414

1515
test 'has correct authorize url' do
16-
assert_equal 'https://www.facebook.com/v4.0/dialog/oauth', strategy.client.options[:authorize_url]
16+
assert_equal "https://www.facebook.com/#{@facebook_api_version}/dialog/oauth", strategy.client.options[:authorize_url]
1717
end
1818

1919
test 'has correct token url with versioning' do
@@ -106,22 +106,22 @@ def setup
106106
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
107107
strategy.stubs(:raw_info).returns(raw_info)
108108
strategy.stubs(:access_token).returns(@access_token)
109-
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token', strategy.info['image']
109+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token", strategy.info['image']
110110
end
111111

112112
test 'returns the non-ssl facebook avatar url when `secure_image_url` option is set to false' do
113113
@options = { secure_image_url: false }
114114
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
115115
strategy.stubs(:raw_info).returns(raw_info)
116116
strategy.stubs(:access_token).returns(@access_token)
117-
assert_equal 'http://graph.facebook.com/v4.0/321/picture?access_token=test_access_token', strategy.info['image']
117+
assert_equal "http://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token", strategy.info['image']
118118
end
119119

120120
test 'returns the secure facebook avatar url when `secure_image_url` option is omitted' do
121121
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
122122
strategy.stubs(:raw_info).returns(raw_info)
123123
strategy.stubs(:access_token).returns(@access_token)
124-
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token', strategy.info['image']
124+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token", strategy.info['image']
125125
end
126126

127127
test 'returns the image_url based of the client site' do
@@ -137,15 +137,15 @@ def setup
137137
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
138138
strategy.stubs(:raw_info).returns(raw_info)
139139
strategy.stubs(:access_token).returns(@access_token)
140-
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token&type=normal', strategy.info['image']
140+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token&type=normal", strategy.info['image']
141141
end
142142

143143
test 'returns the image with size specified as a symbol in the `image_size` option' do
144144
@options = { image_size: :normal }
145145
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
146146
strategy.stubs(:raw_info).returns(raw_info)
147147
strategy.stubs(:access_token).returns(@access_token)
148-
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token&type=normal', strategy.info['image']
148+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token&type=normal", strategy.info['image']
149149
end
150150

151151
test 'returns the image with width and height specified in the `image_size` option' do
@@ -155,7 +155,7 @@ def setup
155155
strategy.stubs(:access_token).returns(@access_token)
156156
assert_match 'width=123', strategy.info['image']
157157
assert_match 'height=987', strategy.info['image']
158-
assert_match 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token', strategy.info['image']
158+
assert_match "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token", strategy.info['image']
159159
end
160160
end
161161

@@ -206,7 +206,7 @@ def setup
206206

207207
test 'returns the facebook avatar url' do
208208
@raw_info['id'] = '321'
209-
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token', strategy.info['image']
209+
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token", strategy.info['image']
210210
end
211211

212212
test 'returns the Facebook link as the Facebook url' do
@@ -292,15 +292,15 @@ def setup
292292
@options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
293293
end
294294

295-
test 'performs a GET to https://graph.facebook.com/v4.0/me' do
295+
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/me" do
296296
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
297297
strategy.stubs(:access_token).returns(@access_token)
298298
params = {params: @options}
299299
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
300300
strategy.raw_info
301301
end
302302

303-
test 'performs a GET to https://graph.facebook.com/v4.0/me with locale' do
303+
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/me with locale" do
304304
@options.merge!({ locale: 'cs_CZ' })
305305
strategy.stubs(:access_token).returns(@access_token)
306306
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
@@ -309,7 +309,7 @@ def setup
309309
strategy.raw_info
310310
end
311311

312-
test 'performs a GET to https://graph.facebook.com/v4.0/me with info_fields' do
312+
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/me with info_fields" do
313313
@options.merge!({info_fields: 'about'})
314314
strategy.stubs(:access_token).returns(@access_token)
315315
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
@@ -318,7 +318,7 @@ def setup
318318
strategy.raw_info
319319
end
320320

321-
test 'performs a GET to https://graph.facebook.com/v4.0/me with default info_fields' do
321+
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/me with default info_fields" do
322322
strategy.stubs(:access_token).returns(@access_token)
323323
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
324324
params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}

0 commit comments

Comments
 (0)