Skip to content

Commit

Permalink
Bump Facebook Graph API to v5.0 (#366)
Browse files Browse the repository at this point in the history
* Add DEFAULT_FACEBOOK_API_VERSION constant
  • Loading branch information
mstr03 committed Oct 25, 2021
1 parent 853dce6 commit 36f8c39
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## 9.0.0 (2021-10-25)

Changes:

- bumped version of FB Graph API to v5.0

## 8.0.0 (2020-10-20)

Changes:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -58,7 +58,7 @@ end

### API Version

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):
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):

```ruby
use OmniAuth::Builder do
Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/facebook/version.rb
@@ -1,5 +1,5 @@
module OmniAuth
module Facebook
VERSION = '8.0.0'
VERSION = '9.0.0'
end
end
5 changes: 3 additions & 2 deletions lib/omniauth/strategies/facebook.rb
Expand Up @@ -10,10 +10,11 @@ class Facebook < OmniAuth::Strategies::OAuth2
class NoAuthorizationCodeError < StandardError; end

DEFAULT_SCOPE = 'email'
DEFAULT_FACEBOOK_API_VERSION = 'v5.0'.freeze

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

Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Expand Up @@ -42,6 +42,8 @@ def setup
@client_id = '123'
@client_secret = '53cr3tz'
@options = {}

@facebook_api_version = OmniAuth::Strategies::Facebook::DEFAULT_FACEBOOK_API_VERSION
end

def strategy
Expand Down
26 changes: 13 additions & 13 deletions test/strategy_test.rb
Expand Up @@ -9,11 +9,11 @@ class StrategyTest < StrategyTestCase

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

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

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

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

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

test 'returns the image_url based of the client site' do
Expand All @@ -137,15 +137,15 @@ def setup
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
strategy.stubs(:access_token).returns(@access_token)
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token&type=normal', strategy.info['image']
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token&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)
strategy.stubs(:access_token).returns(@access_token)
assert_equal 'https://graph.facebook.com/v4.0/321/picture?access_token=test_access_token&type=normal', strategy.info['image']
assert_equal "https://graph.facebook.com/#{@facebook_api_version}/321/picture?access_token=test_access_token&type=normal", strategy.info['image']
end

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

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

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

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

test 'performs a GET to https://graph.facebook.com/v4.0/me' do
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/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/v4.0/me with locale' do
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/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 @@ -309,7 +309,7 @@ def setup
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v4.0/me with info_fields' do
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/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 @@ -318,7 +318,7 @@ def setup
strategy.raw_info
end

test 'performs a GET to https://graph.facebook.com/v4.0/me with default info_fields' do
test "performs a GET to https://graph.facebook.com/#{@facebook_api_version}/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 36f8c39

Please sign in to comment.