Skip to content

Commit

Permalink
Upgrade Facebook Graph API to 4.0
Browse files Browse the repository at this point in the history
The current Facebook Graph API version (v3.0) was only available until
28 July, 2020. This commit upgrades it to v4.0.

----

Version 4.0
Released July 29, 2019 | Available until November 2nd, 2021

https://developers.facebook.com/docs/graph-api/changelog/version4.0
  • Loading branch information
madeleinel authored and simi committed Aug 26, 2020
1 parent 48cdde2 commit c4993ad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 7.0.0 (2020-08-03)

Changes:

- bumped version of FB Graph API to v4.0

## 6.0.0 (2020-01-27)

Changes:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ end

### API Version

OmniAuth Facebook uses versioned API endpoints by default (current v3.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 v4.0 (assuming that exists):
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):

```ruby
use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
client_options: {
site: 'https://graph.facebook.com/v4.0',
authorize_url: "https://www.facebook.com/v4.0/dialog/oauth"
site: 'https://graph.facebook.com/v7.0',
authorize_url: "https://www.facebook.com/v7.0/dialog/oauth"
}
end
```
Expand Down
2 changes: 1 addition & 1 deletion example/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
window.fbAsyncInit = function() {
FB.init({
appId: '#{ENV['FACEBOOK_APP_ID']}',
version: 'v3.0',
version: 'v4.0',
cookie: true // IMPORTANT must enable cookies to allow the server to access the session
});
console.log("fb init");
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/facebook/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module Facebook
VERSION = '6.0.0'
VERSION = '7.0.0'
end
end
4 changes: 2 additions & 2 deletions lib/omniauth/strategies/facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class NoAuthorizationCodeError < StandardError; end
DEFAULT_SCOPE = 'email'

option :client_options, {
site: 'https://graph.facebook.com/v3.0',
authorize_url: "https://www.facebook.com/v3.0/dialog/oauth",
site: 'https://graph.facebook.com/v4.0',
authorize_url: "https://www.facebook.com/v4.0/dialog/oauth",
token_url: 'oauth/access_token'
}

Expand Down
22 changes: 11 additions & 11 deletions test/strategy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class StrategyTest < StrategyTestCase

class ClientTest < StrategyTestCase
test 'has correct Facebook site' do
assert_equal 'https://graph.facebook.com/v3.0', strategy.client.site
assert_equal 'https://graph.facebook.com/v4.0', strategy.client.site
end

test 'has correct authorize url' do
assert_equal 'https://www.facebook.com/v3.0/dialog/oauth', strategy.client.options[:authorize_url]
assert_equal 'https://www.facebook.com/v4.0/dialog/oauth', strategy.client.options[:authorize_url]
end

test 'has correct token url with versioning' do
Expand Down Expand Up @@ -99,7 +99,7 @@ class InfoTest < StrategyTestCase
@options = { secure_image_url: true }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://graph.facebook.com/v3.0/321/picture', strategy.info['image']
assert_equal 'https://graph.facebook.com/v4.0/321/picture', strategy.info['image']
end

test 'returns the image_url based of the client site' do
Expand All @@ -113,14 +113,14 @@ class InfoTest < StrategyTestCase
@options = { image_size: 'normal' }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v3.0/321/picture?type=normal', strategy.info['image']
assert_equal 'http://graph.facebook.com/v4.0/321/picture?type=normal', strategy.info['image']
end

test 'returns the image with size specified as a symbol in the `image_size` option' do
@options = { image_size: :normal }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v3.0/321/picture?type=normal', strategy.info['image']
assert_equal 'http://graph.facebook.com/v4.0/321/picture?type=normal', strategy.info['image']
end

test 'returns the image with width and height specified in the `image_size` option' do
Expand All @@ -129,7 +129,7 @@ class InfoTest < StrategyTestCase
strategy.stubs(:raw_info).returns(raw_info)
assert_match 'width=123', strategy.info['image']
assert_match 'height=987', strategy.info['image']
assert_match 'http://graph.facebook.com/v3.0/321/picture?', strategy.info['image']
assert_match 'http://graph.facebook.com/v4.0/321/picture?', strategy.info['image']
end
end

Expand Down Expand Up @@ -176,7 +176,7 @@ def setup

test 'returns the facebook avatar url' do
@raw_info['id'] = '321'
assert_equal 'http://graph.facebook.com/v3.0/321/picture', strategy.info['image']
assert_equal 'http://graph.facebook.com/v4.0/321/picture', strategy.info['image']
end

test 'returns the Facebook link as the Facebook url' do
Expand Down Expand Up @@ -258,15 +258,15 @@ def setup
@options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
end

test 'performs a GET to https://graph.facebook.com/v3.0/me' do
test 'performs a GET to https://graph.facebook.com/v4.0/me' do
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
strategy.stubs(:access_token).returns(@access_token)
params = {params: @options}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v3.0/me with locale' do
test 'performs a GET to https://graph.facebook.com/v4.0/me with locale' do
@options.merge!({ locale: 'cs_CZ' })
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
Expand All @@ -275,7 +275,7 @@ def setup
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v3.0/me with info_fields' do
test 'performs a GET to https://graph.facebook.com/v4.0/me with info_fields' do
@options.merge!({info_fields: 'about'})
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
Expand All @@ -284,7 +284,7 @@ def setup
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v3.0/me with default info_fields' do
test 'performs a GET to https://graph.facebook.com/v4.0/me with default info_fields' do
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}
Expand Down

0 comments on commit c4993ad

Please # to comment.