diff --git a/.gitignore b/.gitignore index 275f0fe..1d5d65a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,6 @@ /Gemfile.lock pkg/* .powenv +.powder tmp bin -example/app.log diff --git a/.travis.yml b/.travis.yml index 618030d..e863e12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,13 @@ before_install: - gem update bundler - bundle --version - - gem update --system 2.1.11 + - gem update --system - gem --version rvm: - - 1.8.7 - - 1.9.2 + - 2.3.0 + - 2.2 + - 2.1 + - 2.0 - 1.9.3 - - 2.0.0 - - 2.1 - - jruby - - rbx -matrix: - allow_failures: - - rvm: rbx + - jruby-19mode + - rbx-2 diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f22d6..cb0ad8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,29 +1,39 @@ +## 4.0.0 (2016-07-26) + +Changes: + + - drop support for Ruby < 1.9.3 (@mkdynamic) + - switch to versioned FB APIs, currently using v2.6 (#245, @printercu, @mkdynamic) + - remove deprecated :nickname field from README example (#223, @abelorian) + - add Ruby 2.2 + 2.3.0 to CI (#225, @tricknotes, @mkdynamic, @anoraak) + - update example app (@mkynamic) + ## 3.0.0 (2015-10-26) Changes: - - Remove query string from redirect_uri on callback by default (#221, @gioblu) - - Signed request parsing extracted to `OmniAuth::Facebook::SignedRequest` class. (#183, @simi, @Vrael) - - Change default value of `info_fields` to `name,email` for the [graph-api-v2.4](https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/). ([#209](https://github.com/mkdynamic/omniauth-facebook/pull/209)) + - remove query string from redirect_uri on callback by default (#221, @gioblu) + - signed request parsing extracted to `OmniAuth::Facebook::SignedRequest` class. (#183, @simi, @Vrael) + - change default value of `info_fields` to `name,email` for the [graph-api-v2.4](https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/). ([#209](https://github.com/mkdynamic/omniauth-facebook/pull/209)) ## 2.0.1 (2015-02-21) Bugfixes: - - Allow versioning by not forcing absolute path for graph requests (#180, @frausto) - - Allow the image_size option to be set as a symbol. (#182, @jgrau) + - allow versioning by not forcing absolute path for graph requests (#180, @frausto) + - allow the image_size option to be set as a symbol. (#182, @jgrau) ## 2.0.0 (2014-08-07) Changes: - - remove support for canvas app flow (765ed9, @mkdynamic) + - remove support for canvas app flow (765ed9, @mkdynamic) Bugfixes: - - bump omniauth-oauth2 dependency which addresses CVE-2012-6134 (#162, @linedotstar) - - rescue `NoAuthorizationCodeError` in callback_phase (a0036b, @tomoya55) - - fix CSRF exception when using FB JS SDK and parsing signed request (765ed9, @mkdynamic) + - bump omniauth-oauth2 dependency which addresses CVE-2012-6134 (#162, @linedotstar) + - rescue `NoAuthorizationCodeError` in callback_phase (a0036b, @tomoya55) + - fix CSRF exception when using FB JS SDK and parsing signed request (765ed9, @mkdynamic) ## 1.6.0 (2014-01-13) diff --git a/README.md b/README.md index b524e19..b0615ed 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ -**IMPORTANT: If you're running < 1.5.1, please upgrade to the latest version to address 3 security vulnerabilities. -More details [here](https://github.com/mkdynamic/omniauth-facebook/wiki/CSRF-vulnerability:-CVE-2013-4562), [here](https://github.com/mkdynamic/omniauth-facebook/wiki/Access-token-vulnerability:-CVE-2013-4593) and [here](http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2012-6134).** - ---- - # OmniAuth Facebook  [![Build Status](https://secure.travis-ci.org/mkdynamic/omniauth-facebook.svg?branch=master)](https://travis-ci.org/mkdynamic/omniauth-facebook) [![Gem Version](https://img.shields.io/gem/v/omniauth-facebook.svg)](https://rubygems.org/gems/omniauth-facebook) - **These notes are based on master, please see tags for README pertaining to specific releases.** Facebook OAuth2 Strategy for OmniAuth. -Supports the OAuth 2.0 server-side and client-side flows. Read the Facebook docs for more details: http://developers.facebook.com/docs/authentication +Supports OAuth 2.0 server-side and client-side flows. Read the Facebook docs for more details: http://developers.facebook.com/docs/authentication ## Installing @@ -55,24 +49,25 @@ ```ruby Rails.application.config.middleware.use OmniAuth::Builder do - provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], - :scope => 'email,user_birthday,read_stream', :display => 'popup' + provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], + scope: 'email,user_birthday,read_stream', display: 'popup' 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`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v3.0 (assuming that exists): ```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" + client_options: { + site: 'https://graph.facebook.com/v3.0', + authorize_url: "https://www.facebook.com/v3.0/dialog/oauth" } end ``` + ### Per-Request Options If you want to set the `display` format, `auth_type`, or `scope` on a per-request basis, you can just pass it to the OmniAuth request phase URL, for example: `/auth/facebook?display=popup` or `/auth/facebook?scope=email`. @@ -83,39 +78,39 @@ ```ruby { - :provider => 'facebook', - :uid => '1234567', - :info => { - :nickname => 'jbloggs', - :email => 'joe@bloggs.com', - :name => 'Joe Bloggs', - :first_name => 'Joe', - :last_name => 'Bloggs', - :image => 'http://graph.facebook.com/1234567/picture?type=square', - :urls => { :Facebook => 'http://www.facebook.com/jbloggs' }, - :location => 'Palo Alto, California', - :verified => true + provider: 'facebook', + uid: '1234567', + info: { + email: 'joe@bloggs.com', + name: 'Joe Bloggs', + first_name: 'Joe', + last_name: 'Bloggs', + image: 'http://graph.facebook.com/1234567/picture?type=square', + urls: { Facebook: 'http://www.facebook.com/jbloggs' }, + location: 'Palo Alto, California', + verified: true }, - :credentials => { - :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 => true # this will always be true + credentials: { + 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: true # this will always be true }, - :extra => { - :raw_info => { - :id => '1234567', - :name => 'Joe Bloggs', - :first_name => 'Joe', - :last_name => 'Bloggs', - :link => 'http://www.facebook.com/jbloggs', - :username => 'jbloggs', - :location => { :id => '123456789', :name => 'Palo Alto, California' }, - :gender => 'male', - :email => 'joe@bloggs.com', - :timezone => -8, - :locale => 'en_US', - :verified => true, - :updated_time => '2011-11-11T06:21:03+0000' + extra: { + raw_info: { + id: '1234567', + name: 'Joe Bloggs', + first_name: 'Joe', + last_name: 'Bloggs', + link: 'http://www.facebook.com/jbloggs', + username: 'jbloggs', + location: { id: '123456789', name: 'Palo Alto, California' }, + gender: 'male', + email: 'joe@bloggs.com', + timezone: -8, + locale: 'en_US', + verified: true, + updated_time: '2011-11-11T06:21:03+0000', + # ... } } } @@ -157,15 +152,9 @@ ## Supported Rubies -Actively tested with the following Ruby versions: - -- MRI 2.1.0 -- MRI 2.0.0 -- MRI 1.9.3 -- MRI 1.9.2 -- MRI 1.8.7 -- JRuby 1.7.9 -- Rubinius (latest stable) +- Ruby MRI (1.9.3+) +- JRuby (1.9 mode) +- RBX (2.1.1+) ## License @@ -176,6 +165,3 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mkdynamic/omniauth-facebook/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/Rakefile b/Rakefile index 8358d69..f6f9fa4 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,4 @@ task.test_files = FileList['test/*_test.rb'] end -task :default => :test +task default: :test diff --git a/example/Gemfile b/example/Gemfile index 443d6a2..b8ab579 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -2,4 +2,4 @@ gem 'sinatra' gem 'sinatra-reloader' -gem 'omniauth-facebook', :path => '../' +gem 'omniauth-facebook', path: '../' diff --git a/example/Gemfile.lock b/example/Gemfile.lock index 01a53ea..aea783c 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -1,53 +1,51 @@ PATH remote: ../ specs: - omniauth-facebook (2.0.0) + omniauth-facebook (3.0.0) omniauth-oauth2 (~> 1.2) GEM remote: https://rubygems.org/ specs: - backports (3.3.5) - faraday (0.9.0) + backports (3.6.8) + faraday (0.9.2) multipart-post (>= 1.2, < 3) - hashie (3.2.0) - jwt (1.0.0) - multi_json (1.8.2) + hashie (3.4.4) + jwt (1.5.1) + multi_json (1.12.1) multi_xml (0.5.5) multipart-post (2.0.0) - oauth2 (1.0.0) + oauth2 (1.1.0) faraday (>= 0.8, < 0.10) - jwt (~> 1.0) + jwt (~> 1.0, < 1.5.2) multi_json (~> 1.3) multi_xml (~> 0.5) - rack (~> 1.2) - omniauth (1.2.2) + rack (>= 1.2, < 3) + omniauth (1.3.1) hashie (>= 1.2, < 4) - rack (~> 1.0) - omniauth-oauth2 (1.2.0) - faraday (>= 0.8, < 0.10) - multi_json (~> 1.3) + rack (>= 1.0, < 3) + omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) - rack (1.5.2) - rack-protection (1.5.1) + rack (1.6.4) + rack-protection (1.5.3) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) - sinatra (1.4.4) - rack (~> 1.4) + sinatra (1.4.7) + rack (~> 1.5) rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) - sinatra-contrib (1.4.2) + tilt (>= 1.3, < 3) + sinatra-contrib (1.4.7) backports (>= 2.0) multi_json rack-protection rack-test sinatra (~> 1.4.0) - tilt (~> 1.3) + tilt (>= 1.3, < 3) sinatra-reloader (1.0) sinatra-contrib - tilt (1.4.1) + tilt (2.0.5) PLATFORMS ruby @@ -56,3 +54,6 @@ omniauth-facebook! sinatra sinatra-reloader + +BUNDLED WITH + 1.12.5 diff --git a/example/app.rb b/example/app.rb index a078746..47d6514 100644 --- a/example/app.rb +++ b/example/app.rb @@ -6,88 +6,80 @@ set :run, false set :raise_errors, true -# setup logging to file -log = File.new("app.log", "a+") -$stdout.reopen(log) -$stderr.reopen(log) -$stderr.sync = true -$stdout.sync = true - -# server-side flow +# REQUEST STEP (server-side flow) get '/server-side' do - # NOTE: You would just hit this endpoint directly from the browser in a real app. The redirect is just here to - # explicit declare this server-side flow. + # NOTE: You would just hit this endpoint directly from the browser in a real app. The redirect is + # just here to explicit declare this server-side flow. redirect '/auth/facebook' end -# client-side flow +# REQUEST STEP (client-side flow) get '/client-side' do content_type 'text/html' - # NOTE: When you enable cookie below in the FB.init call the GET request in the FB.login callback will send a signed - # request in a cookie back the OmniAuth callback which will parse out the authorization code and obtain an - # access_token with it. - <<-END + # NOTE: When you enable cookie below in the FB.init call the GET request in the FB.login callback + # will send a signed request in a cookie back the OmniAuth callback which will parse out the + # authorization code and obtain an access_token with it. + <<-HTML Client-side Flow Example - + +
- -

Connect to FB!

+ + - END + HTML end +# CALLBACK STEP +# - redirected here for server-side flow +# - ajax request made here for client-side flow get '/auth/:provider/callback' do content_type 'application/json' MultiJson.encode(request.env) end - -get '/auth/failure' do - content_type 'application/json' - MultiJson.encode(request.env) -end diff --git a/example/config.ru b/example/config.ru index 17f0760..c826e0c 100644 --- a/example/config.ru +++ b/example/config.ru @@ -2,10 +2,10 @@ require 'omniauth-facebook' require './app.rb' -use Rack::Session::Cookie, :secret => 'abc123' +use Rack::Session::Cookie, secret: 'abc123' use OmniAuth::Builder do - provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], :scope => 'email,read_stream' + provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'] end run Sinatra::Application diff --git a/lib/omniauth/facebook/version.rb b/lib/omniauth/facebook/version.rb index 34f5686..3b9c88c 100644 --- a/lib/omniauth/facebook/version.rb +++ b/lib/omniauth/facebook/version.rb @@ -1,5 +1,5 @@ module OmniAuth module Facebook - VERSION = "3.0.0" + VERSION = "4.0.0" end end diff --git a/lib/omniauth/strategies/facebook.rb b/lib/omniauth/strategies/facebook.rb index a1d60a3..d73d6ad 100644 --- a/lib/omniauth/strategies/facebook.rb +++ b/lib/omniauth/strategies/facebook.rb @@ -12,18 +12,14 @@ DEFAULT_SCOPE = 'email' option :client_options, { - :site => 'https://graph.facebook.com', - :authorize_url => "https://www.facebook.com/dialog/oauth", - :token_url => 'oauth/access_token' - } - - option :token_params, { - :parse => :query + site: 'https://graph.facebook.com/v2.6', + authorize_url: "https://www.facebook.com/v2.6/dialog/oauth", + token_url: 'oauth/access_token' } option :access_token_options, { - :header_format => 'OAuth %s', - :param_name => 'access_token' + header_format: 'OAuth %s', + param_name: 'access_token' } option :authorize_options, [:scope, :display, :auth_type] @@ -59,11 +55,11 @@ end def info_options - params = {:appsecret_proof => appsecret_proof} - params.merge!({:fields => (options[:info_fields] || 'name,email')}) - params.merge!({:locale => options[:locale]}) if options[:locale] + params = {appsecret_proof: appsecret_proof} + params.merge!({fields: (options[:info_fields] || 'name,email')}) + params.merge!({locale: options[:locale]}) if options[:locale] - { :params => params } + { params: params } end def callback_phase @@ -162,10 +158,10 @@ def image_url(uid, options) uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP 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) - { :type => options[:image_size] } + { type: options[:image_size] } elsif options[:image_size].is_a?(Hash) options[:image_size] end diff --git a/metadata.yml b/metadata.yml deleted file mode 100644 index 6b41ccd..0000000 --- a/metadata.yml +++ /dev/null @@ -1,130 +0,0 @@ ---- !ruby/object:Gem::Specification -name: omniauth-facebook -version: !ruby/object:Gem::Version - version: 3.0.0 -platform: ruby -authors: -- Mark Dodwell -- Josef Šimánek -autorequire: -bindir: bin -cert_chain: [] -date: 2015-10-27 00:00:00.000000000 Z -dependencies: -- !ruby/object:Gem::Dependency - name: omniauth-oauth2 - requirement: !ruby/object:Gem::Requirement - requirements: - - - ~> - - !ruby/object:Gem::Version - version: '1.2' - type: :runtime - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ~> - - !ruby/object:Gem::Version - version: '1.2' -- !ruby/object:Gem::Dependency - name: minitest - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -- !ruby/object:Gem::Dependency - name: mocha - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -- !ruby/object:Gem::Dependency - name: rake - requirement: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -description: -email: -- mark@madeofcode.com -- retro@ballgag.cz -executables: [] -extensions: [] -extra_rdoc_files: [] -files: -- .gitignore -- .travis.yml -- CHANGELOG.md -- Gemfile -- README.md -- Rakefile -- example/Gemfile -- example/Gemfile.lock -- example/app.rb -- example/config.ru -- lib/omniauth-facebook.rb -- lib/omniauth/facebook.rb -- lib/omniauth/facebook/signed_request.rb -- lib/omniauth/facebook/version.rb -- lib/omniauth/strategies/facebook.rb -- omniauth-facebook.gemspec -- test/fixtures/payload.json -- test/fixtures/signed_request.txt -- test/helper.rb -- test/signed_request_test.rb -- test/strategy_test.rb -- test/support/shared_examples.rb -homepage: https://github.com/mkdynamic/omniauth-facebook -licenses: -- MIT -metadata: {} -post_install_message: -rdoc_options: [] -require_paths: -- lib -required_ruby_version: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -required_rubygems_version: !ruby/object:Gem::Requirement - requirements: - - - '>=' - - !ruby/object:Gem::Version - version: '0' -requirements: [] -rubyforge_project: -rubygems_version: 2.0.14 -signing_key: -specification_version: 4 -summary: Facebook OAuth2 Strategy for OmniAuth -test_files: -- test/fixtures/payload.json -- test/fixtures/signed_request.txt -- test/helper.rb -- test/signed_request_test.rb -- test/strategy_test.rb -- test/support/shared_examples.rb diff --git a/test/strategy_test.rb b/test/strategy_test.rb index b5ffdbb..b793c73 100644 --- a/test/strategy_test.rb +++ b/test/strategy_test.rb @@ -9,15 +9,15 @@ 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 - @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 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url end @@ -33,7 +33,7 @@ end 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' @request.stubs(:url).returns("#{url_base}/page/path") strategy.stubs(:script_name).returns('') # as not to depend on Rack env @@ -43,7 +43,7 @@ test "returns url from callback_url option" do url = 'https://auth.myapp.com/auth/fb/callback' - @options = { :callback_url => url } + @options = { callback_url: url } assert_equal url, strategy.callback_url end end @@ -73,12 +73,6 @@ 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] @@ -102,40 +96,40 @@ class InfoTest < StrategyTestCase 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' } 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 - @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' } strategy.stubs(:raw_info).returns(raw_info) assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image'] end 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' } 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 } + @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 - @options = { :image_size => { :width => 123, :height => 987 } } + @options = { image_size: { width: 123, height: 987 } } raw_info = { 'name' => 'Fred Smith', 'id' => '321' } 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 @@ -182,7 +176,7 @@ 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 @@ -261,39 +255,39 @@ super @access_token = stub('OAuth2::AccessToken') @appsecret_proof = 'appsecret_proof' - @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'} - end - - test 'performs a GET to https://graph.facebook.com/me' do + @options = {appsecret_proof: @appsecret_proof, fields: 'name,email'} + end + + 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} + 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 - @options.merge!({ :locale => 'cs_CZ' }) + 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) - params = {:params => @options} + 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 info_fields' do - @options.merge!({:info_fields => 'about'}) + 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) - 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')) 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'}} + params = {params: {appsecret_proof: @appsecret_proof, fields: 'name,email'}} @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response')) strategy.raw_info end @@ -306,7 +300,7 @@ raw_response.stubs(:status).returns(200) raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' }) oauth2_response = OAuth2::Response.new(raw_response) - params = {:params => @options} + params = {params: @options} @access_token.stubs(:get).with('me', params).returns(oauth2_response) assert_kind_of Hash, strategy.raw_info assert_equal 'thar', strategy.raw_info['ohai'] @@ -315,16 +309,16 @@ test 'returns an empty hash when the response is false' do strategy.stubs(:access_token).returns(@access_token) strategy.stubs(:appsecret_proof).returns(@appsecret_proof) - oauth2_response = stub('OAuth2::Response', :parsed => false) - params = {:params => @options} + oauth2_response = stub('OAuth2::Response', parsed: false) + params = {params: @options} @access_token.stubs(:get).with('me', params).returns(oauth2_response) assert_kind_of Hash, strategy.raw_info assert_equal({}, strategy.raw_info) end test 'should not include raw_info in extras hash when skip_info is specified' do - @options = { :skip_info => true } - strategy.stubs(:raw_info).returns({:foo => 'bar' }) + @options = { skip_info: true } + strategy.stubs(:raw_info).returns({foo: 'bar' }) refute_has_key 'raw_info', strategy.extra end end diff --git a/test/support/shared_examples.rb b/test/support/shared_examples.rb index dfbf55f..0c0253a 100644 --- a/test/support/shared_examples.rb +++ b/test/support/shared_examples.rb @@ -13,7 +13,7 @@ extend BlockTestHelper 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] end end @@ -22,19 +22,19 @@ extend BlockTestHelper 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 'zip', strategy.authorize_params['baz'] end 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 'baz', strategy.authorize_params['foo'] end 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 end @@ -51,7 +51,7 @@ end 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_equal 'bar', strategy.authorize_params[:state] refute_empty strategy.session['omniauth.state'] @@ -71,13 +71,13 @@ extend BlockTestHelper 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 'zip', strategy.token_params['baz'] end 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 'baz', strategy.token_params['foo'] end