diff --git a/.travis.yml b/.travis.yml index dc56909..5da81db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ rvm: - - 1.8.7 - - 1.9.2 - 1.9.3 - - ree + - 2.0.0 + - 2.1 + - 2.2 - jruby + - rbx-2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9d6164f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +For the best chance of having your changes merged, please: + +* Fork the project. + +* Make your feature addition or bug fix. + +* Add tests for it. This is important so it is not accidentally broken in a future version. + +* Commit, do not mess with rakefile, version, or history. (If you want to have your own version, that is fine but bump version in a commit by itself so it can be ignored when pulled). + +* Send a pull request. Bonus points for topic branches. + +If your proposed changes only affect documentation, include the following on a +new line in each of your commit messages: + +``` +[ci skip] +``` + +This will signal [Travis](https://travis-ci.org) that running the test suite is +not necessary for these changes. + +# Reporting Bugs + +If you are experiencing unexpected behavior and, after having read [omniauth](https://github.com/intridea/omniauth) and [omniauth-twitter](https://github.com/arunagw/omniauth-twitter)'s documentation, are convinced this behavior is a bug, please: + +1. [Search](https://github.com/arunagw/omniauth-twitter/issues) existing issues. +2. Collect enough information to reproduce the issue: + + * omniauth-twitter version + + * Ruby version + + * Specific setup conditions + + * Description of expected behavior + + * Description of actual behavior diff --git a/Gemfile b/Gemfile index ffe885c..3b0b968 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,12 @@ -source "https://rubygems.org" +source 'https://rubygems.org' + +gemspec gem 'rake' -# Specify your gem's dependencies in omniauth-twitter.gemspec -gemspec + +group :test do + gem 'rspec', '~> 3.2' + gem 'rack-test' + gem 'simplecov' + gem 'webmock' +end diff --git a/README.md b/README.md index 88b221a..901c344 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,20 @@ # OmniAuth Twitter + +[![Gem Version](https://badge.fury.io/rb/omniauth-twitter.svg)](http://badge.fury.io/rb/omniauth-twitter) +[![CI Build Status](https://secure.travis-ci.org/arunagw/omniauth-twitter.svg?branch=master)](http://travis-ci.org/arunagw/omniauth-twitter) +[![Code Climate](https://codeclimate.com/github/arunagw/omniauth-twitter.png)](https://codeclimate.com/github/arunagw/omniauth-twitter) This gem contains the Twitter strategy for OmniAuth. Twitter offers a few different methods of integration. This strategy implements the browser variant of the "[Sign in with Twitter](https://dev.twitter.com/docs/auth/implementing-sign-twitter)" flow. -Twitter uses OAuth 1.0a. Twitter's developer area contains ample documentation on how it implements this, so if you are really interested in the details, go check that out for more. +Twitter uses OAuth 1.0a. Twitter's developer area contains ample documentation on how it implements this, so check that out if you are really interested in the details. ## Before You Begin You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started. -Now sign in into the [Twitter developer area](http://dev.twitter.com) and create an application. Take note of your Consumer Key and Consumer Secret (not the Access Token and Secret) because that is what your web application will use to authenticate against the Twitter API. Make sure to set a callback URL or else you may get authentication errors. (It doesn't matter what it is, just that it is set.) +Now sign in into the [Twitter developer area](https://dev.twitter.com/apps) and create an application. Take note of your API Key and API Secret (not the Access Token and Access Token Secret) because that is what your web application will use to authenticate against the Twitter API. Make sure to set a callback URL or else you may get authentication errors. (It doesn't matter what it is, just that it is set.) ## Using This Strategy @@ -30,11 +34,11 @@ ```ruby Rails.application.config.middleware.use OmniAuth::Builder do - provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET" + provider :twitter, "API_KEY", "API_SECRET" end ``` -Replace CONSUMER_KEY and CONSUMER_SECRET with the appropriate values you obtained from dev.twitter.com earlier. +Replace `"API_KEY"` and `"API_SECRET"` with the appropriate values you obtained [earlier](https://apps.twitter.com). ## Authentication Options @@ -60,7 +64,7 @@ ```ruby Rails.application.config.middleware.use OmniAuth::Builder do - provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"], + provider :twitter, "API_KEY", "API_SECRET", { :secure_image_url => 'true', :image_size => 'original', @@ -98,8 +102,8 @@ :access_token => "", # An OAuth::AccessToken object :raw_info => { :name => "John Q Public", - :listed_count" => 0, - :profile_sidebar_border_color" => "181A1E", + :listed_count => 0, + :profile_sidebar_border_color => "181A1E", :url => nil, :lang => "en", :statuses_count => 129, @@ -152,18 +156,11 @@ ## Supported Rubies -OmniAuth Twitter is tested under 1.8.7, 1.9.2, 1.9.3 and Ruby Enterprise Edition. +OmniAuth Twitter is tested under 1.9.3, 2.0.0, 2.1.x, 2.2.x, JRuby, and Rubinius. -[![CI Build -Status](https://secure.travis-ci.org/arunagw/omniauth-twitter.png)](http://travis-ci.org/arunagw/omniauth-twitter) +## Contributing -## Note on Patches/Pull Requests - -- Fork the project. -- Make your feature addition or bug fix. -- Add tests for it. This is important so I don’t break it in a future version unintentionally. -- Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) -- Send me a pull request. Bonus points for topic branches. +Please read the [contribution guidelines](CONTRIBUTING.md) for some information on how to get started. No contribution is too small. ## License diff --git a/checksums.yaml.gz b/checksums.yaml.gz deleted file mode 100644 index a35ac4f..0000000 Binary files a/checksums.yaml.gz and /dev/null differ diff --git a/lib/omniauth/strategies/twitter.rb b/lib/omniauth/strategies/twitter.rb index d29c548..a68bb15 100644 --- a/lib/omniauth/strategies/twitter.rb +++ b/lib/omniauth/strategies/twitter.rb @@ -1,5 +1,5 @@ require 'omniauth-oauth' -require 'multi_json' +require 'json' module OmniAuth module Strategies @@ -27,11 +27,11 @@ end extra do - { :raw_info => raw_info } + skip_info? ? {} : { :raw_info => raw_info } end def raw_info - @raw_info ||= MultiJson.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body) + @raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body) rescue ::Errno::ETIMEDOUT raise ::Timeout::Error end @@ -51,7 +51,7 @@ end end - if request.params['use_authorize'] == 'true' + if options[:use_authorize] || request.params['use_authorize'] == 'true' options[:client_options][:authorize_path] = '/oauth/authorize' else options[:client_options][:authorize_path] = '/oauth/authenticate' diff --git a/lib/omniauth-twitter/version.rb b/lib/omniauth-twitter/version.rb index a060640..ffdd9d7 100644 --- a/lib/omniauth-twitter/version.rb +++ b/lib/omniauth-twitter/version.rb @@ -1,5 +1,5 @@ module OmniAuth module Twitter - VERSION = "1.0.1" + VERSION = "1.2.0" end end diff --git a/metadata.yml b/metadata.yml index 7c4f319..a429b96 100644 --- a/metadata.yml +++ b/metadata.yml @@ -1,17 +1,17 @@ --- !ruby/object:Gem::Specification name: omniauth-twitter version: !ruby/object:Gem::Version - version: 1.0.1 + version: 1.2.0 platform: ruby authors: - Arun Agrawal autorequire: bindir: bin cert_chain: [] -date: 2013-10-04 00:00:00.000000000 Z +date: 2015-04-22 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency - name: multi_json + name: json requirement: !ruby/object:Gem::Requirement requirements: - - ~> @@ -30,70 +30,28 @@ requirements: - - ~> - !ruby/object:Gem::Version - version: '1.0' + version: '1.1' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version - version: '1.0' + version: '1.1' - !ruby/object:Gem::Dependency - name: rspec + name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version - version: '2.7' + version: '1.0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version - version: '2.7' -- !ruby/object:Gem::Dependency - name: rack-test - 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: simplecov - 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: webmock - 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' + version: '1.0' description: OmniAuth strategy for Twitter email: - arunagw@gmail.com @@ -104,6 +62,7 @@ - .gitignore - .rspec - .travis.yml +- CONTRIBUTING.md - Gemfile - README.md - Rakefile @@ -132,8 +91,8 @@ - !ruby/object:Gem::Version version: '0' requirements: [] -rubyforge_project: omniauth-twitter -rubygems_version: 2.0.6 +rubyforge_project: +rubygems_version: 2.0.14 signing_key: specification_version: 4 summary: OmniAuth strategy for Twitter diff --git a/omniauth-twitter.gemspec b/omniauth-twitter.gemspec index 4f7abc7..4a0440d 100644 --- a/omniauth-twitter.gemspec +++ b/omniauth-twitter.gemspec @@ -8,21 +8,16 @@ s.authors = ["Arun Agrawal"] s.email = ["arunagw@gmail.com"] s.homepage = "https://github.com/arunagw/omniauth-twitter" - s.summary = %q{OmniAuth strategy for Twitter} s.description = %q{OmniAuth strategy for Twitter} + s.summary = s.description s.license = "MIT" - - s.rubyforge_project = "omniauth-twitter" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'multi_json', '~> 1.3' - s.add_runtime_dependency 'omniauth-oauth', '~> 1.0' - s.add_development_dependency 'rspec', '~> 2.7' - s.add_development_dependency 'rack-test' - s.add_development_dependency 'simplecov' - s.add_development_dependency 'webmock' + s.add_dependency 'json', '~> 1.3' + s.add_dependency 'omniauth-oauth', '~> 1.1' + s.add_development_dependency 'bundler', '~> 1.0' end diff --git a/spec/omniauth/strategies/twitter_spec.rb b/spec/omniauth/strategies/twitter_spec.rb index 36b42a1..8b9f4d2 100644 --- a/spec/omniauth/strategies/twitter_spec.rb +++ b/spec/omniauth/strategies/twitter_spec.rb @@ -6,7 +6,7 @@ subject do args = ['appid', 'secret', @options || {}].compact OmniAuth::Strategies::Twitter.new(*args).tap do |strategy| - strategy.stub(:request) { + allow(strategy).to receive(:request) { request } end @@ -30,22 +30,30 @@ context 'when user has an image' do it 'should return image with size specified' do @options = { :image_size => 'original' } - subject.stub(:raw_info).and_return( + allow(subject).to receive(:raw_info).and_return( { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } ) expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png') end + it 'should return bigger image when bigger size specified' do + @options = { :image_size => 'bigger' } + allow(subject).to receive(:raw_info).and_return( + { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } + ) + expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_bigger.png') + end + it 'should return secure image with size specified' do @options = { :secure_image_url => 'true', :image_size => 'mini' } - subject.stub(:raw_info).and_return( + allow(subject).to receive(:raw_info).and_return( { 'profile_image_url_https' => 'https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } ) expect(subject.info[:image]).to eq('https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_mini.png') end it 'should return normal image by default' do - subject.stub(:raw_info).and_return( + allow(subject).to receive(:raw_info).and_return( { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } ) expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png') @@ -53,18 +61,55 @@ end end + describe 'skip_info option' do + context 'when skip info option is enabled' do + it 'should not include raw_info in extras hash' do + @options = { :skip_info => true } + allow(subject).to receive(:raw_info).and_return({:foo => 'bar'}) + expect(subject.extra[:raw_info]).to eq(nil) + end + end + end + describe 'request_phase' do context 'with no request params set and x_auth_access_type specified' do before do - subject.stub(:request).and_return( + allow(subject).to receive(:request).and_return( double('Request', {:params => {'x_auth_access_type' => 'read'}}) ) - subject.stub(:old_request_phase).and_return(:whatever) + allow(subject).to receive(:old_request_phase).and_return(:whatever) end it 'should not break' do expect { subject.request_phase }.not_to raise_error end end + + context "with no request params set and use_authorize options provided" do + before do + @options = { :use_authorize => true } + allow(subject).to receive(:request) do + double('Request', {:params => {} }) + end + allow(subject).to receive(:old_request_phase) { :whatever } + end + + it "should switch authorize_path from authenticate to authorize" do + expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize') + end + end + + context "with no request params set and force_login specified" do + before do + allow(subject).to receive(:request) do + double('Request', {:params => { 'force_login' => true } }) + end + allow(subject).to receive(:old_request_phase) { :whatever } + end + + it "should change add force_login=true to authorize_params" do + expect { subject.request_phase }.to change {subject.options.authorize_params.force_login}.from(nil).to(true) + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6600c41..d26919e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,9 @@ $:.unshift File.expand_path('..', __FILE__) $:.unshift File.expand_path('../../lib', __FILE__) require 'simplecov' -SimpleCov.start +SimpleCov.start do + minimum_coverage(94.59) +end require 'rspec' require 'rack/test' require 'webmock/rspec'