Codebase list ruby-omniauth-facebook / d7379d4
upgrade to verioned API endpoints (2.6). re: #245 Mark Dodwell 7 years ago
4 changed file(s) with 17 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
6161
6262 ### API Version
6363
64 OmniAuth Facebook uses unversioned API endpoints by default. You can configure custom endpoints via `client_options` hash passed to `provider`.
64 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:
6565
6666 ```ruby
6767 use OmniAuth::Builder do
6868 provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
6969 :client_options => {
70 :site => 'https://graph.facebook.com/v2.0',
71 :authorize_url => "https://www.facebook.com/v2.0/dialog/oauth"
70 :site => 'https://graph.facebook.com/v2.6',
71 :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth"
7272 }
7373 end
7474 ```
2727 window.fbAsyncInit = function() {
2828 FB.init({
2929 appId: '#{ENV['APP_ID']}',
30 version: 'v2.6',
3031 cookie: true // IMPORTANT must enable cookies to allow the server to access the session
3132 });
3233 console.log("fb init");
1111 DEFAULT_SCOPE = 'email'
1212
1313 option :client_options, {
14 :site => 'https://graph.facebook.com',
15 :authorize_url => "https://www.facebook.com/dialog/oauth",
14 :site => 'https://graph.facebook.com/v2.6',
15 :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth",
1616 :token_url => 'oauth/access_token'
17 }
18
19 option :token_params, {
20 :parse => :query
2117 }
2218
2319 option :access_token_options, {
88
99 class ClientTest < StrategyTestCase
1010 test 'has correct Facebook site' do
11 assert_equal 'https://graph.facebook.com', strategy.client.site
11 assert_equal 'https://graph.facebook.com/v2.6', strategy.client.site
1212 end
1313
1414 test 'has correct authorize url' do
15 assert_equal 'https://www.facebook.com/dialog/oauth', strategy.client.options[:authorize_url]
15 assert_equal 'https://www.facebook.com/v2.6/dialog/oauth', strategy.client.options[:authorize_url]
1616 end
1717
1818 test 'has correct token url with versioning' do
7272 end
7373 end
7474
75 class TokeParamsTest < StrategyTestCase
76 test 'has correct parse strategy' do
77 assert_equal :query, strategy.token_params[:parse]
78 end
79 end
80
8175 class AccessTokenOptionsTest < StrategyTestCase
8276 test 'has correct param name by default' do
8377 assert_equal 'access_token', strategy.access_token_options[:param_name]
10498 @options = { :secure_image_url => true }
10599 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
106100 strategy.stubs(:raw_info).returns(raw_info)
107 assert_equal 'https://graph.facebook.com/321/picture', strategy.info['image']
101 assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image']
108102 end
109103
110104 test 'returns the image_url based of the client site' do
118112 @options = { :image_size => 'normal' }
119113 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
120114 strategy.stubs(:raw_info).returns(raw_info)
121 assert_equal 'http://graph.facebook.com/321/picture?type=normal', strategy.info['image']
115 assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
122116 end
123117
124118 test 'returns the image with size specified as a symbol in the `image_size` option' do
125119 @options = { :image_size => :normal }
126120 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
127121 strategy.stubs(:raw_info).returns(raw_info)
128 assert_equal 'http://graph.facebook.com/321/picture?type=normal', strategy.info['image']
122 assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
129123 end
130124
131125 test 'returns the image with width and height specified in the `image_size` option' do
134128 strategy.stubs(:raw_info).returns(raw_info)
135129 assert_match 'width=123', strategy.info['image']
136130 assert_match 'height=987', strategy.info['image']
137 assert_match 'http://graph.facebook.com/321/picture?', strategy.info['image']
131 assert_match 'http://graph.facebook.com/v2.6/321/picture?', strategy.info['image']
138132 end
139133 end
140134
181175
182176 test 'returns the facebook avatar url' do
183177 @raw_info['id'] = '321'
184 assert_equal 'http://graph.facebook.com/321/picture', strategy.info['image']
178 assert_equal 'http://graph.facebook.com/v2.6/321/picture', strategy.info['image']
185179 end
186180
187181 test 'returns the Facebook link as the Facebook url' do
263257 @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}
264258 end
265259
266 test 'performs a GET to https://graph.facebook.com/me' do
260 test 'performs a GET to https://graph.facebook.com/v2.6/me' do
267261 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
268262 strategy.stubs(:access_token).returns(@access_token)
269263 params = {:params => @options}
271265 strategy.raw_info
272266 end
273267
274 test 'performs a GET to https://graph.facebook.com/me with locale' do
268 test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do
275269 @options.merge!({ :locale => 'cs_CZ' })
276270 strategy.stubs(:access_token).returns(@access_token)
277271 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
280274 strategy.raw_info
281275 end
282276
283 test 'performs a GET to https://graph.facebook.com/me with info_fields' do
277 test 'performs a GET to https://graph.facebook.com/v2.6/me with info_fields' do
284278 @options.merge!({:info_fields => 'about'})
285279 strategy.stubs(:access_token).returns(@access_token)
286280 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
289283 strategy.raw_info
290284 end
291285
292 test 'performs a GET to https://graph.facebook.com/me with default info_fields' do
286 test 'performs a GET to https://graph.facebook.com/v2.6/me with default info_fields' do
293287 strategy.stubs(:access_token).returns(@access_token)
294288 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
295289 params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}}