1
0
Fork 0
mirror of https://github.com/simi/omniauth-facebook.git synced 2022-11-09 12:32:45 -05:00

remove support for ruby < 1.9, upgrade hash syntax

This commit is contained in:
Mark Dodwell 2016-06-26 17:44:08 -07:00
parent 28207f3d82
commit edc21693ba
9 changed files with 86 additions and 99 deletions

View file

@ -4,14 +4,12 @@ before_install:
- gem update --system 2.1.11 - gem update --system 2.1.11
- gem --version - gem --version
rvm: rvm:
- 1.8.7 - 2.3
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1
- 2.2 - 2.2
- jruby - 2.1
- rbx - 2.0
matrix: - 1.9.3
allow_failures: - 1.9.2
- rvm: rbx - jruby-19mode
- rbx-2
- ree

View file

@ -2,10 +2,6 @@ source 'https://rubygems.org'
gemspec gemspec
platforms :ruby_18 do
gem 'hashie', '~> 2.0.5'
end
platforms :rbx do platforms :rbx do
gem 'rubysl', '~> 2.0' gem 'rubysl', '~> 2.0'
end end

View file

@ -56,7 +56,7 @@ For example, to request `email`, `user_birthday` and `read_stream` permissions a
```ruby ```ruby
Rails.application.config.middleware.use OmniAuth::Builder do Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
:scope => 'email,user_birthday,read_stream', :display => 'popup' scope: 'email,user_birthday,read_stream', display: 'popup'
end end
``` ```
@ -67,9 +67,9 @@ OmniAuth Facebook uses versioned API endpoints by default (current v2.6). You ca
```ruby ```ruby
use OmniAuth::Builder do use OmniAuth::Builder do
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'],
:client_options => { client_options: {
:site => 'https://graph.facebook.com/v2.6', site: 'https://graph.facebook.com/v2.6',
:authorize_url => "https://www.facebook.com/v2.6/dialog/oauth" authorize_url: "https://www.facebook.com/v2.6/dialog/oauth"
} }
end end
``` ```
@ -84,38 +84,38 @@ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
```ruby ```ruby
{ {
:provider => 'facebook', provider: 'facebook',
:uid => '1234567', uid: '1234567',
:info => { info: {
:email => 'joe@bloggs.com', email: 'joe@bloggs.com',
:name => 'Joe Bloggs', name: 'Joe Bloggs',
:first_name => 'Joe', first_name: 'Joe',
:last_name => 'Bloggs', last_name: 'Bloggs',
:image => 'http://graph.facebook.com/1234567/picture?type=square', image: 'http://graph.facebook.com/1234567/picture?type=square',
:urls => { :Facebook => 'http://www.facebook.com/jbloggs' }, urls: { Facebook: 'http://www.facebook.com/jbloggs' },
:location => 'Palo Alto, California', location: 'Palo Alto, California',
:verified => true verified: true
}, },
:credentials => { credentials: {
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
:expires_at => 1321747205, # when the access token expires (it always will) expires_at: 1321747205, # when the access token expires (it always will)
:expires => true # this will always be true expires: true # this will always be true
}, },
:extra => { extra: {
:raw_info => { raw_info: {
:id => '1234567', id: '1234567',
:name => 'Joe Bloggs', name: 'Joe Bloggs',
:first_name => 'Joe', first_name: 'Joe',
:last_name => 'Bloggs', last_name: 'Bloggs',
:link => 'http://www.facebook.com/jbloggs', link: 'http://www.facebook.com/jbloggs',
:username => 'jbloggs', username: 'jbloggs',
:location => { :id => '123456789', :name => 'Palo Alto, California' }, location: { id: '123456789', name: 'Palo Alto, California' },
:gender => 'male', gender: 'male',
:email => 'joe@bloggs.com', email: 'joe@bloggs.com',
:timezone => -8, timezone: -8,
:locale => 'en_US', locale: 'en_US',
:verified => true, verified: true,
:updated_time => '2011-11-11T06:21:03+0000' updated_time: '2011-11-11T06:21:03+0000'
} }
} }
} }
@ -157,16 +157,9 @@ If you use the server-side flow, Facebook will give you back a longer lived acce
## Supported Rubies ## Supported Rubies
Actively tested with the following Ruby versions: - Ruby MRI (1.9.2+)
- JRuby (1.9 mode)
- MRI 2.2 - RBX (2.1.1+)
- MRI 2.1
- MRI 2.0.0
- MRI 1.9.3
- MRI 1.9.2
- MRI 1.8.7 (use hashie ~> 2.0.5 in your Gemfile)
- JRuby 1.7.9
- Rubinius (latest stable)
## License ## License

View file

@ -6,4 +6,4 @@ Rake::TestTask.new do |task|
task.test_files = FileList['test/*_test.rb'] task.test_files = FileList['test/*_test.rb']
end end
task :default => :test task default: :test

View file

@ -2,4 +2,4 @@ source 'https://rubygems.org'
gem 'sinatra' gem 'sinatra'
gem 'sinatra-reloader' gem 'sinatra-reloader'
gem 'omniauth-facebook', :path => '../' gem 'omniauth-facebook', path: '../'

View file

@ -2,7 +2,7 @@ require 'bundler/setup'
require 'omniauth-facebook' require 'omniauth-facebook'
require './app.rb' require './app.rb'
use Rack::Session::Cookie, :secret => 'abc123' use Rack::Session::Cookie, secret: 'abc123'
use OmniAuth::Builder do use OmniAuth::Builder do
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'] provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']

View file

@ -12,14 +12,14 @@ module OmniAuth
DEFAULT_SCOPE = 'email' DEFAULT_SCOPE = 'email'
option :client_options, { option :client_options, {
:site => 'https://graph.facebook.com/v2.6', site: 'https://graph.facebook.com/v2.6',
:authorize_url => "https://www.facebook.com/v2.6/dialog/oauth", authorize_url: "https://www.facebook.com/v2.6/dialog/oauth",
:token_url => 'oauth/access_token' token_url: 'oauth/access_token'
} }
option :access_token_options, { option :access_token_options, {
:header_format => 'OAuth %s', header_format: 'OAuth %s',
:param_name => 'access_token' param_name: 'access_token'
} }
option :authorize_options, [:scope, :display, :auth_type] option :authorize_options, [:scope, :display, :auth_type]
@ -55,11 +55,11 @@ module OmniAuth
end end
def info_options def info_options
params = {:appsecret_proof => appsecret_proof} params = {appsecret_proof: appsecret_proof}
params.merge!({:fields => (options[:info_fields] || 'name,email')}) params.merge!({fields: (options[:info_fields] || 'name,email')})
params.merge!({:locale => options[:locale]}) if options[:locale] params.merge!({locale: options[:locale]}) if options[:locale]
{ :params => params } { params: params }
end end
def callback_phase def callback_phase
@ -158,10 +158,10 @@ module OmniAuth
def image_url(uid, options) def image_url(uid, options)
uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
site_uri = URI.parse(client.site) site_uri = URI.parse(client.site)
url = uri_class.build({:host => site_uri.host, :path => "#{site_uri.path}/#{uid}/picture"}) url = uri_class.build({host: site_uri.host, path: "#{site_uri.path}/#{uid}/picture"})
query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol) query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol)
{ :type => options[:image_size] } { type: options[:image_size] }
elsif options[:image_size].is_a?(Hash) elsif options[:image_size].is_a?(Hash)
options[:image_size] options[:image_size]
end end

View file

@ -17,7 +17,7 @@ class ClientTest < StrategyTestCase
end end
test 'has correct token url with versioning' do test 'has correct token url with versioning' do
@options = {:client_options => {:site => 'https://graph.facebook.net/v2.2'}} @options = {client_options: {site: 'https://graph.facebook.net/v2.2'}}
assert_equal 'oauth/access_token', strategy.client.options[:token_url] assert_equal 'oauth/access_token', strategy.client.options[:token_url]
assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url
end end
@ -33,7 +33,7 @@ class CallbackUrlTest < StrategyTestCase
end end
test "returns path from callback_path option (omitting querystring)" do test "returns path from callback_path option (omitting querystring)" do
@options = { :callback_path => "/auth/FB/done"} @options = { callback_path: "/auth/FB/done"}
url_base = 'http://auth.request.com' url_base = 'http://auth.request.com'
@request.stubs(:url).returns("#{url_base}/page/path") @request.stubs(:url).returns("#{url_base}/page/path")
strategy.stubs(:script_name).returns('') # as not to depend on Rack env strategy.stubs(:script_name).returns('') # as not to depend on Rack env
@ -43,7 +43,7 @@ class CallbackUrlTest < StrategyTestCase
test "returns url from callback_url option" do test "returns url from callback_url option" do
url = 'https://auth.myapp.com/auth/fb/callback' url = 'https://auth.myapp.com/auth/fb/callback'
@options = { :callback_url => url } @options = { callback_url: url }
assert_equal url, strategy.callback_url assert_equal url, strategy.callback_url
end end
end end
@ -96,35 +96,35 @@ end
class InfoTest < StrategyTestCase class InfoTest < StrategyTestCase
test 'returns the secure facebook avatar url when `secure_image_url` option is specified' do test 'returns the secure facebook avatar url when `secure_image_url` option is specified' do
@options = { :secure_image_url => true } @options = { secure_image_url: true }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info) strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image'] assert_equal 'https://graph.facebook.com/v2.6/321/picture', strategy.info['image']
end end
test 'returns the image_url based of the client site' do test 'returns the image_url based of the client site' do
@options = { :secure_image_url => true, :client_options => {:site => "https://blah.facebook.com/v2.2"}} @options = { secure_image_url: true, client_options: {site: "https://blah.facebook.com/v2.2"}}
raw_info = { 'name' => 'Fred Smith', 'id' => '321' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info) strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image'] assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image']
end end
test 'returns the image with size specified in the `image_size` option' do test 'returns the image with size specified in the `image_size` option' do
@options = { :image_size => 'normal' } @options = { image_size: 'normal' }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info) strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
end end
test 'returns the image with size specified as a symbol in the `image_size` option' do test 'returns the image with size specified as a symbol in the `image_size` option' do
@options = { :image_size => :normal } @options = { image_size: :normal }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info) strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image'] assert_equal 'http://graph.facebook.com/v2.6/321/picture?type=normal', strategy.info['image']
end end
test 'returns the image with width and height specified in the `image_size` option' do test 'returns the image with width and height specified in the `image_size` option' do
@options = { :image_size => { :width => 123, :height => 987 } } @options = { image_size: { width: 123, height: 987 } }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' } raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info) strategy.stubs(:raw_info).returns(raw_info)
assert_match 'width=123', strategy.info['image'] assert_match 'width=123', strategy.info['image']
@ -255,31 +255,31 @@ class RawInfoTest < StrategyTestCase
super super
@access_token = stub('OAuth2::AccessToken') @access_token = stub('OAuth2::AccessToken')
@appsecret_proof = 'appsecret_proof' @appsecret_proof = 'appsecret_proof'
@options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'} @options = {appsecret_proof: @appsecret_proof, fields: 'name,email'}
end end
test 'performs a GET to https://graph.facebook.com/v2.6/me' do test 'performs a GET to https://graph.facebook.com/v2.6/me' do
strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:access_token).returns(@access_token)
params = {:params => @options} params = {params: @options}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info strategy.raw_info
end end
test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do test 'performs a GET to https://graph.facebook.com/v2.6/me with locale' do
@options.merge!({ :locale => 'cs_CZ' }) @options.merge!({ locale: 'cs_CZ' })
strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => @options} params = {params: @options}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info strategy.raw_info
end end
test 'performs a GET to https://graph.facebook.com/v2.6/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'}) @options.merge!({info_fields: 'about'})
strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}} params = {params: {appsecret_proof: @appsecret_proof, fields: 'about'}}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info strategy.raw_info
end end
@ -287,7 +287,7 @@ class RawInfoTest < StrategyTestCase
test 'performs a GET to https://graph.facebook.com/v2.6/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(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}} params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}}
@access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info strategy.raw_info
end end
@ -300,7 +300,7 @@ class RawInfoTest < StrategyTestCase
raw_response.stubs(:status).returns(200) raw_response.stubs(:status).returns(200)
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' }) raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
oauth2_response = OAuth2::Response.new(raw_response) oauth2_response = OAuth2::Response.new(raw_response)
params = {:params => @options} params = {params: @options}
@access_token.stubs(:get).with('me', params).returns(oauth2_response) @access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info assert_kind_of Hash, strategy.raw_info
assert_equal 'thar', strategy.raw_info['ohai'] assert_equal 'thar', strategy.raw_info['ohai']
@ -309,16 +309,16 @@ class RawInfoTest < StrategyTestCase
test 'returns an empty hash when the response is false' do test 'returns an empty hash when the response is false' do
strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof) strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
oauth2_response = stub('OAuth2::Response', :parsed => false) oauth2_response = stub('OAuth2::Response', parsed: false)
params = {:params => @options} params = {params: @options}
@access_token.stubs(:get).with('me', params).returns(oauth2_response) @access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info assert_kind_of Hash, strategy.raw_info
assert_equal({}, strategy.raw_info) assert_equal({}, strategy.raw_info)
end end
test 'should not include raw_info in extras hash when skip_info is specified' do test 'should not include raw_info in extras hash when skip_info is specified' do
@options = { :skip_info => true } @options = { skip_info: true }
strategy.stubs(:raw_info).returns({:foo => 'bar' }) strategy.stubs(:raw_info).returns({foo: 'bar' })
refute_has_key 'raw_info', strategy.extra refute_has_key 'raw_info', strategy.extra
end end
end end

View file

@ -13,7 +13,7 @@ module OAuth2StrategyTests
extend BlockTestHelper extend BlockTestHelper
test 'should be initialized with symbolized client_options' do test 'should be initialized with symbolized client_options' do
@options = { :client_options => { 'authorize_url' => 'https://example.com' } } @options = { client_options: { 'authorize_url' => 'https://example.com' } }
assert_equal 'https://example.com', strategy.client.options[:authorize_url] assert_equal 'https://example.com', strategy.client.options[:authorize_url]
end end
end end
@ -22,19 +22,19 @@ module OAuth2StrategyTests
extend BlockTestHelper extend BlockTestHelper
test 'should include any authorize params passed in the :authorize_params option' do test 'should include any authorize params passed in the :authorize_params option' do
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } } @options = { authorize_params: { foo: 'bar', baz: 'zip' } }
assert_equal 'bar', strategy.authorize_params['foo'] assert_equal 'bar', strategy.authorize_params['foo']
assert_equal 'zip', strategy.authorize_params['baz'] assert_equal 'zip', strategy.authorize_params['baz']
end end
test 'should include top-level options that are marked as :authorize_options' do test 'should include top-level options that are marked as :authorize_options' do
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } @options = { authorize_options: [:scope, :foo], scope: 'bar', foo: 'baz' }
assert_equal 'bar', strategy.authorize_params['scope'] assert_equal 'bar', strategy.authorize_params['scope']
assert_equal 'baz', strategy.authorize_params['foo'] assert_equal 'baz', strategy.authorize_params['foo']
end end
test 'should exclude top-level options that are not passed' do test 'should exclude top-level options that are not passed' do
@options = { :authorize_options => [:bar] } @options = { authorize_options: [:bar] }
refute_has_key :bar, strategy.authorize_params refute_has_key :bar, strategy.authorize_params
refute_has_key 'bar', strategy.authorize_params refute_has_key 'bar', strategy.authorize_params
end end
@ -51,7 +51,7 @@ module OAuth2StrategyTests
end end
test 'should not store state in the session when present in authorize params vs. a random one' do test 'should not store state in the session when present in authorize params vs. a random one' do
@options = { :authorize_params => { :state => 'bar' } } @options = { authorize_params: { state: 'bar' } }
refute_empty strategy.authorize_params['state'] refute_empty strategy.authorize_params['state']
refute_equal 'bar', strategy.authorize_params[:state] refute_equal 'bar', strategy.authorize_params[:state]
refute_empty strategy.session['omniauth.state'] refute_empty strategy.session['omniauth.state']
@ -71,13 +71,13 @@ module OAuth2StrategyTests
extend BlockTestHelper extend BlockTestHelper
test 'should include any authorize params passed in the :token_params option' do test 'should include any authorize params passed in the :token_params option' do
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } } @options = { token_params: { foo: 'bar', baz: 'zip' } }
assert_equal 'bar', strategy.token_params['foo'] assert_equal 'bar', strategy.token_params['foo']
assert_equal 'zip', strategy.token_params['baz'] assert_equal 'zip', strategy.token_params['baz']
end end
test 'should include top-level options that are marked as :token_options' do test 'should include top-level options that are marked as :token_options' do
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' } @options = { token_options: [:scope, :foo], scope: 'bar', foo: 'baz' }
assert_equal 'bar', strategy.token_params['scope'] assert_equal 'bar', strategy.token_params['scope']
assert_equal 'baz', strategy.token_params['foo'] assert_equal 'baz', strategy.token_params['foo']
end end