Skip to content

Commit

Permalink
upgrade to verioned API endpoints (2.6). re: simi#245
Browse files Browse the repository at this point in the history
  • Loading branch information
mkdynamic committed Jun 27, 2016
1 parent 89809cc commit d7379d4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 1 addition & 0 deletions example/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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");
Expand Down
8 changes: 2 additions & 6 deletions lib/omniauth/strategies/facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ class NoAuthorizationCodeError < StandardError; end
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'
Expand Down
28 changes: 11 additions & 17 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', 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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

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

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
Expand Down Expand Up @@ -264,15 +258,15 @@ def setup
@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}
@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/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)
Expand All @@ -281,7 +275,7 @@ def setup
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)
Expand All @@ -290,7 +284,7 @@ def setup
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'}}
Expand Down

0 comments on commit d7379d4

Please sign in to comment.