Codebase list ruby-omniauth-facebook / edc2169
remove support for ruby < 1.9, upgrade hash syntax Mark Dodwell 7 years ago
9 changed file(s) with 86 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
33 - gem update --system 2.1.11
44 - gem --version
55 rvm:
6 - 1.8.7
6 - 2.3
7 - 2.2
8 - 2.1
9 - 2.0
10 - 1.9.3
711 - 1.9.2
8 - 1.9.3
9 - 2.0.0
10 - 2.1
11 - 2.2
12 - jruby
13 - rbx
14 matrix:
15 allow_failures:
16 - rvm: rbx
12 - jruby-19mode
13 - rbx-2
14 - ree
11
22 gemspec
33
4 platforms :ruby_18 do
5 gem 'hashie', '~> 2.0.5'
6 end
7
84 platforms :rbx do
95 gem 'rubysl', '~> 2.0'
106 end
5555 ```ruby
5656 Rails.application.config.middleware.use OmniAuth::Builder do
5757 provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
58 :scope => 'email,user_birthday,read_stream', :display => 'popup'
58 scope: 'email,user_birthday,read_stream', display: 'popup'
5959 end
6060 ```
6161
6666 ```ruby
6767 use OmniAuth::Builder do
6868 provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
69 :client_options => {
70 :site => 'https://graph.facebook.com/v2.6',
71 :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth"
69 client_options: {
70 site: 'https://graph.facebook.com/v2.6',
71 authorize_url: "https://www.facebook.com/v2.6/dialog/oauth"
7272 }
7373 end
7474 ```
8383
8484 ```ruby
8585 {
86 :provider => 'facebook',
87 :uid => '1234567',
88 :info => {
89 :email => 'joe@bloggs.com',
90 :name => 'Joe Bloggs',
91 :first_name => 'Joe',
92 :last_name => 'Bloggs',
93 :image => 'http://graph.facebook.com/1234567/picture?type=square',
94 :urls => { :Facebook => 'http://www.facebook.com/jbloggs' },
95 :location => 'Palo Alto, California',
96 :verified => true
86 provider: 'facebook',
87 uid: '1234567',
88 info: {
89 email: 'joe@bloggs.com',
90 name: 'Joe Bloggs',
91 first_name: 'Joe',
92 last_name: 'Bloggs',
93 image: 'http://graph.facebook.com/1234567/picture?type=square',
94 urls: { Facebook: 'http://www.facebook.com/jbloggs' },
95 location: 'Palo Alto, California',
96 verified: true
9797 },
98 :credentials => {
99 :token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
100 :expires_at => 1321747205, # when the access token expires (it always will)
101 :expires => true # this will always be true
98 credentials: {
99 token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
100 expires_at: 1321747205, # when the access token expires (it always will)
101 expires: true # this will always be true
102102 },
103 :extra => {
104 :raw_info => {
105 :id => '1234567',
106 :name => 'Joe Bloggs',
107 :first_name => 'Joe',
108 :last_name => 'Bloggs',
109 :link => 'http://www.facebook.com/jbloggs',
110 :username => 'jbloggs',
111 :location => { :id => '123456789', :name => 'Palo Alto, California' },
112 :gender => 'male',
113 :email => 'joe@bloggs.com',
114 :timezone => -8,
115 :locale => 'en_US',
116 :verified => true,
117 :updated_time => '2011-11-11T06:21:03+0000'
103 extra: {
104 raw_info: {
105 id: '1234567',
106 name: 'Joe Bloggs',
107 first_name: 'Joe',
108 last_name: 'Bloggs',
109 link: 'http://www.facebook.com/jbloggs',
110 username: 'jbloggs',
111 location: { id: '123456789', name: 'Palo Alto, California' },
112 gender: 'male',
113 email: 'joe@bloggs.com',
114 timezone: -8,
115 locale: 'en_US',
116 verified: true,
117 updated_time: '2011-11-11T06:21:03+0000'
118118 }
119119 }
120120 }
156156
157157 ## Supported Rubies
158158
159 Actively tested with the following Ruby versions:
160
161 - MRI 2.2
162 - MRI 2.1
163 - MRI 2.0.0
164 - MRI 1.9.3
165 - MRI 1.9.2
166 - MRI 1.8.7 (use hashie ~> 2.0.5 in your Gemfile)
167 - JRuby 1.7.9
168 - Rubinius (latest stable)
159 - Ruby MRI (1.9.2+)
160 - JRuby (1.9 mode)
161 - RBX (2.1.1+)
169162
170163 ## License
171164
55 task.test_files = FileList['test/*_test.rb']
66 end
77
8 task :default => :test
8 task default: :test
11
22 gem 'sinatra'
33 gem 'sinatra-reloader'
4 gem 'omniauth-facebook', :path => '../'
4 gem 'omniauth-facebook', path: '../'
11 require 'omniauth-facebook'
22 require './app.rb'
33
4 use Rack::Session::Cookie, :secret => 'abc123'
4 use Rack::Session::Cookie, secret: 'abc123'
55
66 use OmniAuth::Builder do
77 provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']
1111 DEFAULT_SCOPE = 'email'
1212
1313 option :client_options, {
14 :site => 'https://graph.facebook.com/v2.6',
15 :authorize_url => "https://www.facebook.com/v2.6/dialog/oauth",
16 :token_url => 'oauth/access_token'
14 site: 'https://graph.facebook.com/v2.6',
15 authorize_url: "https://www.facebook.com/v2.6/dialog/oauth",
16 token_url: 'oauth/access_token'
1717 }
1818
1919 option :access_token_options, {
20 :header_format => 'OAuth %s',
21 :param_name => 'access_token'
20 header_format: 'OAuth %s',
21 param_name: 'access_token'
2222 }
2323
2424 option :authorize_options, [:scope, :display, :auth_type]
5454 end
5555
5656 def info_options
57 params = {:appsecret_proof => appsecret_proof}
58 params.merge!({:fields => (options[:info_fields] || 'name,email')})
59 params.merge!({:locale => options[:locale]}) if options[:locale]
57 params = {appsecret_proof: appsecret_proof}
58 params.merge!({fields: (options[:info_fields] || 'name,email')})
59 params.merge!({locale: options[:locale]}) if options[:locale]
6060
61 { :params => params }
61 { params: params }
6262 end
6363
6464 def callback_phase
157157 def image_url(uid, options)
158158 uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
159159 site_uri = URI.parse(client.site)
160 url = uri_class.build({:host => site_uri.host, :path => "#{site_uri.path}/#{uid}/picture"})
160 url = uri_class.build({host: site_uri.host, path: "#{site_uri.path}/#{uid}/picture"})
161161
162162 query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol)
163 { :type => options[:image_size] }
163 { type: options[:image_size] }
164164 elsif options[:image_size].is_a?(Hash)
165165 options[:image_size]
166166 end
1616 end
1717
1818 test 'has correct token url with versioning' do
19 @options = {:client_options => {:site => 'https://graph.facebook.net/v2.2'}}
19 @options = {client_options: {site: 'https://graph.facebook.net/v2.2'}}
2020 assert_equal 'oauth/access_token', strategy.client.options[:token_url]
2121 assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url
2222 end
3232 end
3333
3434 test "returns path from callback_path option (omitting querystring)" do
35 @options = { :callback_path => "/auth/FB/done"}
35 @options = { callback_path: "/auth/FB/done"}
3636 url_base = 'http://auth.request.com'
3737 @request.stubs(:url).returns("#{url_base}/page/path")
3838 strategy.stubs(:script_name).returns('') # as not to depend on Rack env
4242
4343 test "returns url from callback_url option" do
4444 url = 'https://auth.myapp.com/auth/fb/callback'
45 @options = { :callback_url => url }
45 @options = { callback_url: url }
4646 assert_equal url, strategy.callback_url
4747 end
4848 end
9595
9696 class InfoTest < StrategyTestCase
9797 test 'returns the secure facebook avatar url when `secure_image_url` option is specified' do
98 @options = { :secure_image_url => true }
98 @options = { secure_image_url: true }
9999 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
100100 strategy.stubs(:raw_info).returns(raw_info)
101101 assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image']
102102 end
103103
104104 test 'returns the image_url based of the client site' do
105 @options = { :secure_image_url => true, :client_options => {:site => "https://blah.facebook.com/v2.2"}}
105 @options = { secure_image_url: true, client_options: {site: "https://blah.facebook.com/v2.2"}}
106106 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
107107 strategy.stubs(:raw_info).returns(raw_info)
108108 assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image']
109109 end
110110
111111 test 'returns the image with size specified in the `image_size` option' do
112 @options = { :image_size => 'normal' }
112 @options = { image_size: 'normal' }
113113 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
114114 strategy.stubs(:raw_info).returns(raw_info)
115115 assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
116116 end
117117
118118 test 'returns the image with size specified as a symbol in the `image_size` option' do
119 @options = { :image_size => :normal }
119 @options = { image_size: :normal }
120120 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
121121 strategy.stubs(:raw_info).returns(raw_info)
122122 assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
123123 end
124124
125125 test 'returns the image with width and height specified in the `image_size` option' do
126 @options = { :image_size => { :width => 123, :height => 987 } }
126 @options = { image_size: { width: 123, height: 987 } }
127127 raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
128128 strategy.stubs(:raw_info).returns(raw_info)
129129 assert_match 'width=123', strategy.info['image']
254254 super
255255 @access_token = stub('OAuth2::AccessToken')
256256 @appsecret_proof = 'appsecret_proof'
257 @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}
257 @options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
258258 end
259259
260260 test 'performs a GET to https://graph.facebook.com/v2.6/me' do
261261 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
262262 strategy.stubs(:access_token).returns(@access_token)
263 params = {:params => @options}
263 params = {params: @options}
264264 @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
265265 strategy.raw_info
266266 end
267267
268268 test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do
269 @options.merge!({ :locale => 'cs_CZ' })
269 @options.merge!({ locale: 'cs_CZ' })
270270 strategy.stubs(:access_token).returns(@access_token)
271271 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
272 params = {:params => @options}
272 params = {params: @options}
273273 @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
274274 strategy.raw_info
275275 end
276276
277277 test 'performs a GET to https://graph.facebook.com/v2.6/me with info_fields' do
278 @options.merge!({:info_fields => 'about'})
278 @options.merge!({info_fields: 'about'})
279279 strategy.stubs(:access_token).returns(@access_token)
280280 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
281 params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}}
281 params = {params: {appsecret_proof: @appsecret_proof, fields: 'about'}}
282282 @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
283283 strategy.raw_info
284284 end
286286 test 'performs a GET to https://graph.facebook.com/v2.6/me with default info_fields' do
287287 strategy.stubs(:access_token).returns(@access_token)
288288 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
289 params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}}
289 params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}
290290 @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
291291 strategy.raw_info
292292 end
299299 raw_response.stubs(:status).returns(200)
300300 raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
301301 oauth2_response = OAuth2::Response.new(raw_response)
302 params = {:params => @options}
302 params = {params: @options}
303303 @access_token.stubs(:get).with('me', params).returns(oauth2_response)
304304 assert_kind_of Hash, strategy.raw_info
305305 assert_equal 'thar', strategy.raw_info['ohai']
308308 test 'returns an empty hash when the response is false' do
309309 strategy.stubs(:access_token).returns(@access_token)
310310 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
311 oauth2_response = stub('OAuth2::Response', :parsed => false)
312 params = {:params => @options}
311 oauth2_response = stub('OAuth2::Response', parsed: false)
312 params = {params: @options}
313313 @access_token.stubs(:get).with('me', params).returns(oauth2_response)
314314 assert_kind_of Hash, strategy.raw_info
315315 assert_equal({}, strategy.raw_info)
316316 end
317317
318318 test 'should not include raw_info in extras hash when skip_info is specified' do
319 @options = { :skip_info => true }
320 strategy.stubs(:raw_info).returns({:foo => 'bar' })
319 @options = { skip_info: true }
320 strategy.stubs(:raw_info).returns({foo: 'bar' })
321321 refute_has_key 'raw_info', strategy.extra
322322 end
323323 end
1212 extend BlockTestHelper
1313
1414 test 'should be initialized with symbolized client_options' do
15 @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
15 @options = { client_options: { 'authorize_url' => 'https://example.com' } }
1616 assert_equal 'https://example.com', strategy.client.options[:authorize_url]
1717 end
1818 end
2121 extend BlockTestHelper
2222
2323 test 'should include any authorize params passed in the :authorize_params option' do
24 @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
24 @options = { authorize_params: { foo: 'bar', baz: 'zip' } }
2525 assert_equal 'bar', strategy.authorize_params['foo']
2626 assert_equal 'zip', strategy.authorize_params['baz']
2727 end
2828
2929 test 'should include top-level options that are marked as :authorize_options' do
30 @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
30 @options = { authorize_options: [:scope, :foo], scope: 'bar', foo: 'baz' }
3131 assert_equal 'bar', strategy.authorize_params['scope']
3232 assert_equal 'baz', strategy.authorize_params['foo']
3333 end
3434
3535 test 'should exclude top-level options that are not passed' do
36 @options = { :authorize_options => [:bar] }
36 @options = { authorize_options: [:bar] }
3737 refute_has_key :bar, strategy.authorize_params
3838 refute_has_key 'bar', strategy.authorize_params
3939 end
5050 end
5151
5252 test 'should not store state in the session when present in authorize params vs. a random one' do
53 @options = { :authorize_params => { :state => 'bar' } }
53 @options = { authorize_params: { state: 'bar' } }
5454 refute_empty strategy.authorize_params['state']
5555 refute_equal 'bar', strategy.authorize_params[:state]
5656 refute_empty strategy.session['omniauth.state']
7070 extend BlockTestHelper
7171
7272 test 'should include any authorize params passed in the :token_params option' do
73 @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
73 @options = { token_params: { foo: 'bar', baz: 'zip' } }
7474 assert_equal 'bar', strategy.token_params['foo']
7575 assert_equal 'zip', strategy.token_params['baz']
7676 end
7777
7878 test 'should include top-level options that are marked as :token_options' do
79 @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
79 @options = { token_options: [:scope, :foo], scope: 'bar', foo: 'baz' }
8080 assert_equal 'bar', strategy.token_params['scope']
8181 assert_equal 'baz', strategy.token_params['foo']
8282 end