remove support for ruby < 1.9, upgrade hash syntax
Mark Dodwell
7 years ago
3 | 3 | - gem update --system 2.1.11 |
4 | 4 | - gem --version |
5 | 5 | rvm: |
6 | - 1.8.7 | |
6 | - 2.3 | |
7 | - 2.2 | |
8 | - 2.1 | |
9 | - 2.0 | |
10 | - 1.9.3 | |
7 | 11 | - 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 |
1 | 1 | |
2 | 2 | gemspec |
3 | 3 | |
4 | platforms :ruby_18 do | |
5 | gem 'hashie', '~> 2.0.5' | |
6 | end | |
7 | ||
8 | 4 | platforms :rbx do |
9 | 5 | gem 'rubysl', '~> 2.0' |
10 | 6 | end |
55 | 55 | ```ruby |
56 | 56 | Rails.application.config.middleware.use OmniAuth::Builder do |
57 | 57 | 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' | |
59 | 59 | end |
60 | 60 | ``` |
61 | 61 | |
66 | 66 | ```ruby |
67 | 67 | use OmniAuth::Builder do |
68 | 68 | 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" | |
72 | 72 | } |
73 | 73 | end |
74 | 74 | ``` |
83 | 83 | |
84 | 84 | ```ruby |
85 | 85 | { |
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 | |
97 | 97 | }, |
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 | |
102 | 102 | }, |
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' | |
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
156 | 156 | |
157 | 157 | ## Supported Rubies |
158 | 158 | |
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+) | |
169 | 162 | |
170 | 163 | ## License |
171 | 164 |
5 | 5 | task.test_files = FileList['test/*_test.rb'] |
6 | 6 | end |
7 | 7 | |
8 | task :default => :test | |
8 | task default: :test |
1 | 1 | |
2 | 2 | gem 'sinatra' |
3 | 3 | gem 'sinatra-reloader' |
4 | gem 'omniauth-facebook', :path => '../' | |
4 | gem 'omniauth-facebook', path: '../' |
1 | 1 | require 'omniauth-facebook' |
2 | 2 | require './app.rb' |
3 | 3 | |
4 | use Rack::Session::Cookie, :secret => 'abc123' | |
4 | use Rack::Session::Cookie, secret: 'abc123' | |
5 | 5 | |
6 | 6 | use OmniAuth::Builder do |
7 | 7 | provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'] |
11 | 11 | DEFAULT_SCOPE = 'email' |
12 | 12 | |
13 | 13 | 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' | |
17 | 17 | } |
18 | 18 | |
19 | 19 | option :access_token_options, { |
20 | :header_format => 'OAuth %s', | |
21 | :param_name => 'access_token' | |
20 | header_format: 'OAuth %s', | |
21 | param_name: 'access_token' | |
22 | 22 | } |
23 | 23 | |
24 | 24 | option :authorize_options, [:scope, :display, :auth_type] |
54 | 54 | end |
55 | 55 | |
56 | 56 | 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] | |
60 | 60 | |
61 | { :params => params } | |
61 | { params: params } | |
62 | 62 | end |
63 | 63 | |
64 | 64 | def callback_phase |
157 | 157 | def image_url(uid, options) |
158 | 158 | uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP |
159 | 159 | 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"}) | |
161 | 161 | |
162 | 162 | query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol) |
163 | { :type => options[:image_size] } | |
163 | { type: options[:image_size] } | |
164 | 164 | elsif options[:image_size].is_a?(Hash) |
165 | 165 | options[:image_size] |
166 | 166 | end |
16 | 16 | end |
17 | 17 | |
18 | 18 | 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'}} | |
20 | 20 | assert_equal 'oauth/access_token', strategy.client.options[:token_url] |
21 | 21 | assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url |
22 | 22 | end |
32 | 32 | end |
33 | 33 | |
34 | 34 | test "returns path from callback_path option (omitting querystring)" do |
35 | @options = { :callback_path => "/auth/FB/done"} | |
35 | @options = { callback_path: "/auth/FB/done"} | |
36 | 36 | url_base = 'http://auth.request.com' |
37 | 37 | @request.stubs(:url).returns("#{url_base}/page/path") |
38 | 38 | strategy.stubs(:script_name).returns('') # as not to depend on Rack env |
42 | 42 | |
43 | 43 | test "returns url from callback_url option" do |
44 | 44 | url = 'https://auth.myapp.com/auth/fb/callback' |
45 | @options = { :callback_url => url } | |
45 | @options = { callback_url: url } | |
46 | 46 | assert_equal url, strategy.callback_url |
47 | 47 | end |
48 | 48 | end |
95 | 95 | |
96 | 96 | class InfoTest < StrategyTestCase |
97 | 97 | 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 } | |
99 | 99 | raw_info = { 'name' => 'Fred Smith', 'id' => '321' } |
100 | 100 | strategy.stubs(:raw_info).returns(raw_info) |
101 | 101 | assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image'] |
102 | 102 | end |
103 | 103 | |
104 | 104 | 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"}} | |
106 | 106 | raw_info = { 'name' => 'Fred Smith', 'id' => '321' } |
107 | 107 | strategy.stubs(:raw_info).returns(raw_info) |
108 | 108 | assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image'] |
109 | 109 | end |
110 | 110 | |
111 | 111 | test 'returns the image with size specified in the `image_size` option' do |
112 | @options = { :image_size => 'normal' } | |
112 | @options = { image_size: 'normal' } | |
113 | 113 | raw_info = { 'name' => 'Fred Smith', 'id' => '321' } |
114 | 114 | strategy.stubs(:raw_info).returns(raw_info) |
115 | 115 | assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] |
116 | 116 | end |
117 | 117 | |
118 | 118 | 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 } | |
120 | 120 | raw_info = { 'name' => 'Fred Smith', 'id' => '321' } |
121 | 121 | strategy.stubs(:raw_info).returns(raw_info) |
122 | 122 | assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] |
123 | 123 | end |
124 | 124 | |
125 | 125 | 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 } } | |
127 | 127 | raw_info = { 'name' => 'Fred Smith', 'id' => '321' } |
128 | 128 | strategy.stubs(:raw_info).returns(raw_info) |
129 | 129 | assert_match 'width=123', strategy.info['image'] |
254 | 254 | super |
255 | 255 | @access_token = stub('OAuth2::AccessToken') |
256 | 256 | @appsecret_proof = 'appsecret_proof' |
257 | @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'} | |
257 | @options = {appsecret_proof: @appsecret_proof, fields: 'name,email'} | |
258 | 258 | end |
259 | 259 | |
260 | 260 | test 'performs a GET to https://graph.facebook.com/v2.6/me' do |
261 | 261 | strategy.stubs(:appsecret_proof).returns(@appsecret_proof) |
262 | 262 | strategy.stubs(:access_token).returns(@access_token) |
263 | params = {:params => @options} | |
263 | params = {params: @options} | |
264 | 264 | @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) |
265 | 265 | strategy.raw_info |
266 | 266 | end |
267 | 267 | |
268 | 268 | 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' }) | |
270 | 270 | strategy.stubs(:access_token).returns(@access_token) |
271 | 271 | strategy.stubs(:appsecret_proof).returns(@appsecret_proof) |
272 | params = {:params => @options} | |
272 | params = {params: @options} | |
273 | 273 | @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) |
274 | 274 | strategy.raw_info |
275 | 275 | end |
276 | 276 | |
277 | 277 | 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'}) | |
279 | 279 | strategy.stubs(:access_token).returns(@access_token) |
280 | 280 | 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'}} | |
282 | 282 | @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) |
283 | 283 | strategy.raw_info |
284 | 284 | end |
286 | 286 | test 'performs a GET to https://graph.facebook.com/v2.6/me with default info_fields' do |
287 | 287 | strategy.stubs(:access_token).returns(@access_token) |
288 | 288 | 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'}} | |
290 | 290 | @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) |
291 | 291 | strategy.raw_info |
292 | 292 | end |
299 | 299 | raw_response.stubs(:status).returns(200) |
300 | 300 | raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' }) |
301 | 301 | oauth2_response = OAuth2::Response.new(raw_response) |
302 | params = {:params => @options} | |
302 | params = {params: @options} | |
303 | 303 | @access_token.stubs(:get).with('me', params).returns(oauth2_response) |
304 | 304 | assert_kind_of Hash, strategy.raw_info |
305 | 305 | assert_equal 'thar', strategy.raw_info['ohai'] |
308 | 308 | test 'returns an empty hash when the response is false' do |
309 | 309 | strategy.stubs(:access_token).returns(@access_token) |
310 | 310 | 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} | |
313 | 313 | @access_token.stubs(:get).with('me', params).returns(oauth2_response) |
314 | 314 | assert_kind_of Hash, strategy.raw_info |
315 | 315 | assert_equal({}, strategy.raw_info) |
316 | 316 | end |
317 | 317 | |
318 | 318 | 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' }) | |
321 | 321 | refute_has_key 'raw_info', strategy.extra |
322 | 322 | end |
323 | 323 | end |
12 | 12 | extend BlockTestHelper |
13 | 13 | |
14 | 14 | 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' } } | |
16 | 16 | assert_equal 'https://example.com', strategy.client.options[:authorize_url] |
17 | 17 | end |
18 | 18 | end |
21 | 21 | extend BlockTestHelper |
22 | 22 | |
23 | 23 | 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' } } | |
25 | 25 | assert_equal 'bar', strategy.authorize_params['foo'] |
26 | 26 | assert_equal 'zip', strategy.authorize_params['baz'] |
27 | 27 | end |
28 | 28 | |
29 | 29 | 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' } | |
31 | 31 | assert_equal 'bar', strategy.authorize_params['scope'] |
32 | 32 | assert_equal 'baz', strategy.authorize_params['foo'] |
33 | 33 | end |
34 | 34 | |
35 | 35 | test 'should exclude top-level options that are not passed' do |
36 | @options = { :authorize_options => [:bar] } | |
36 | @options = { authorize_options: [:bar] } | |
37 | 37 | refute_has_key :bar, strategy.authorize_params |
38 | 38 | refute_has_key 'bar', strategy.authorize_params |
39 | 39 | end |
50 | 50 | end |
51 | 51 | |
52 | 52 | 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' } } | |
54 | 54 | refute_empty strategy.authorize_params['state'] |
55 | 55 | refute_equal 'bar', strategy.authorize_params[:state] |
56 | 56 | refute_empty strategy.session['omniauth.state'] |
70 | 70 | extend BlockTestHelper |
71 | 71 | |
72 | 72 | 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' } } | |
74 | 74 | assert_equal 'bar', strategy.token_params['foo'] |
75 | 75 | assert_equal 'zip', strategy.token_params['baz'] |
76 | 76 | end |
77 | 77 | |
78 | 78 | 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' } | |
80 | 80 | assert_equal 'bar', strategy.token_params['scope'] |
81 | 81 | assert_equal 'baz', strategy.token_params['foo'] |
82 | 82 | end |