diff --git a/README.md b/README.md index 0194211..d9d03a1 100644 --- a/README.md +++ b/README.md @@ -62,14 +62,14 @@ end ### API Version -OmniAuth Facebook uses unversioned API endpoints by default. You can configure custom endpoints via `client_options` hash passed to `provider`. +OmniAuth Facebook uses versioned API endpoints by default (current v2.6). You can configure a different version via `client_options` hash passed to `provider`. For example: ```ruby use OmniAuth::Builder do provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], :client_options => { - :site => 'https://graph.facebook.com/v2.0', - :authorize_url => "https://www.facebook.com/v2.0/dialog/oauth" + :site => 'https://graph.facebook.com/v2.6', + :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth" } end ``` diff --git a/example/app.rb b/example/app.rb index 142da58..47d6514 100644 --- a/example/app.rb +++ b/example/app.rb @@ -28,6 +28,7 @@ get '/client-side' do window.fbAsyncInit = function() { FB.init({ appId: '#{ENV['APP_ID']}', + version: 'v2.6', cookie: true // IMPORTANT must enable cookies to allow the server to access the session }); console.log("fb init"); diff --git a/lib/omniauth/strategies/facebook.rb b/lib/omniauth/strategies/facebook.rb index a1d60a3..6f9662f 100644 --- a/lib/omniauth/strategies/facebook.rb +++ b/lib/omniauth/strategies/facebook.rb @@ -12,15 +12,11 @@ module OmniAuth DEFAULT_SCOPE = 'email' option :client_options, { - :site => 'https://graph.facebook.com', - :authorize_url => "https://www.facebook.com/dialog/oauth", + :site => 'https://graph.facebook.com/v2.6', + :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth", :token_url => 'oauth/access_token' } - option :token_params, { - :parse => :query - } - option :access_token_options, { :header_format => 'OAuth %s', :param_name => 'access_token' diff --git a/test/strategy_test.rb b/test/strategy_test.rb index b5ffdbb..19210f5 100644 --- a/test/strategy_test.rb +++ b/test/strategy_test.rb @@ -9,11 +9,11 @@ end class ClientTest < StrategyTestCase test 'has correct Facebook site' do - assert_equal 'https://graph.facebook.com', strategy.client.site + assert_equal 'https://graph.facebook.com/v2.6', strategy.client.site end test 'has correct authorize url' do - assert_equal 'https://www.facebook.com/dialog/oauth', strategy.client.options[:authorize_url] + assert_equal 'https://www.facebook.com/v2.6/dialog/oauth', strategy.client.options[:authorize_url] end test 'has correct token url with versioning' do @@ -73,12 +73,6 @@ class AuthorizeParamsTest < StrategyTestCase end end -class TokeParamsTest < StrategyTestCase - test 'has correct parse strategy' do - assert_equal :query, strategy.token_params[:parse] - end -end - class AccessTokenOptionsTest < StrategyTestCase test 'has correct param name by default' do assert_equal 'access_token', strategy.access_token_options[:param_name] @@ -105,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/321/picture', strategy.info['image'] + assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image'] end test 'returns the image_url based of the client site' do @@ -119,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/321/picture?type=normal', strategy.info['image'] + assert_equal 'http://graph.facebook.com/v2.6/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/321/picture?type=normal', strategy.info['image'] + assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] end test 'returns the image with width and height specified in the `image_size` option' do @@ -135,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/321/picture?', strategy.info['image'] + assert_match 'http://graph.facebook.com/v2.6/321/picture?', strategy.info['image'] end end @@ -182,7 +176,7 @@ class InfoTestOptionalDataPresent < StrategyTestCase test 'returns the facebook avatar url' do @raw_info['id'] = '321' - assert_equal 'http://graph.facebook.com/321/picture', strategy.info['image'] + assert_equal 'http://graph.facebook.com/v2.6/321/picture', strategy.info['image'] end test 'returns the Facebook link as the Facebook url' do @@ -264,7 +258,7 @@ class RawInfoTest < StrategyTestCase @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'} end - test 'performs a GET to https://graph.facebook.com/me' do + test 'performs a GET to https://graph.facebook.com/v2.6/me' do strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:access_token).returns(@access_token) params = {:params => @options} @@ -272,7 +266,7 @@ class RawInfoTest < StrategyTestCase strategy.raw_info end - test 'performs a GET to https://graph.facebook.com/me with locale' do + test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do @options.merge!({ :locale => 'cs_CZ' }) strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) @@ -281,7 +275,7 @@ class RawInfoTest < StrategyTestCase strategy.raw_info end - test 'performs a GET to https://graph.facebook.com/me with info_fields' do + test 'performs a GET to https://graph.facebook.com/v2.6/me with info_fields' do @options.merge!({:info_fields => 'about'}) strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) @@ -290,7 +284,7 @@ class RawInfoTest < StrategyTestCase strategy.raw_info end - test 'performs a GET to https://graph.facebook.com/me with default info_fields' do + test 'performs a GET to https://graph.facebook.com/v2.6/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'}}