Imported Upstream version 1.2.0
Praveen Arimbrathodiyil
8 years ago
0 | # Contributing | |
1 | ||
2 | For the best chance of having your changes merged, please: | |
3 | ||
4 | * Fork the project. | |
5 | ||
6 | * Make your feature addition or bug fix. | |
7 | ||
8 | * Add tests for it. This is important so it is not accidentally broken in a future version. | |
9 | ||
10 | * 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). | |
11 | ||
12 | * Send a pull request. Bonus points for topic branches. | |
13 | ||
14 | If your proposed changes only affect documentation, include the following on a | |
15 | new line in each of your commit messages: | |
16 | ||
17 | ``` | |
18 | [ci skip] | |
19 | ``` | |
20 | ||
21 | This will signal [Travis](https://travis-ci.org) that running the test suite is | |
22 | not necessary for these changes. | |
23 | ||
24 | # Reporting Bugs | |
25 | ||
26 | 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: | |
27 | ||
28 | 1. [Search](https://github.com/arunagw/omniauth-twitter/issues) existing issues. | |
29 | 2. Collect enough information to reproduce the issue: | |
30 | ||
31 | * omniauth-twitter version | |
32 | ||
33 | * Ruby version | |
34 | ||
35 | * Specific setup conditions | |
36 | ||
37 | * Description of expected behavior | |
38 | ||
39 | * Description of actual behavior |
0 | source "https://rubygems.org" | |
0 | source 'https://rubygems.org' | |
1 | ||
2 | gemspec | |
1 | 3 | |
2 | 4 | gem 'rake' |
3 | # Specify your gem's dependencies in omniauth-twitter.gemspec | |
4 | gemspec | |
5 | ||
6 | group :test do | |
7 | gem 'rspec', '~> 3.2' | |
8 | gem 'rack-test' | |
9 | gem 'simplecov' | |
10 | gem 'webmock' | |
11 | end |
0 | 0 | # OmniAuth Twitter |
1 | ||
2 | [](http://badge.fury.io/rb/omniauth-twitter) | |
3 | [](http://travis-ci.org/arunagw/omniauth-twitter) | |
4 | [](https://codeclimate.com/github/arunagw/omniauth-twitter) | |
1 | 5 | |
2 | 6 | This gem contains the Twitter strategy for OmniAuth. |
3 | 7 | |
4 | 8 | 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. |
5 | 9 | |
6 | 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. | |
10 | 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. | |
7 | 11 | |
8 | 12 | ## Before You Begin |
9 | 13 | |
10 | 14 | You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started. |
11 | 15 | |
12 | 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.) | |
16 | 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.) | |
13 | 17 | |
14 | 18 | ## Using This Strategy |
15 | 19 | |
29 | 33 | |
30 | 34 | ```ruby |
31 | 35 | Rails.application.config.middleware.use OmniAuth::Builder do |
32 | provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET" | |
36 | provider :twitter, "API_KEY", "API_SECRET" | |
33 | 37 | end |
34 | 38 | ``` |
35 | 39 | |
36 | Replace CONSUMER_KEY and CONSUMER_SECRET with the appropriate values you obtained from dev.twitter.com earlier. | |
40 | Replace `"API_KEY"` and `"API_SECRET"` with the appropriate values you obtained [earlier](https://apps.twitter.com). | |
37 | 41 | |
38 | 42 | ## Authentication Options |
39 | 43 | |
59 | 63 | |
60 | 64 | ```ruby |
61 | 65 | Rails.application.config.middleware.use OmniAuth::Builder do |
62 | provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"], | |
66 | provider :twitter, "API_KEY", "API_SECRET", | |
63 | 67 | { |
64 | 68 | :secure_image_url => 'true', |
65 | 69 | :image_size => 'original', |
97 | 101 | :access_token => "", # An OAuth::AccessToken object |
98 | 102 | :raw_info => { |
99 | 103 | :name => "John Q Public", |
100 | :listed_count" => 0, | |
101 | :profile_sidebar_border_color" => "181A1E", | |
104 | :listed_count => 0, | |
105 | :profile_sidebar_border_color => "181A1E", | |
102 | 106 | :url => nil, |
103 | 107 | :lang => "en", |
104 | 108 | :statuses_count => 129, |
151 | 155 | |
152 | 156 | ## Supported Rubies |
153 | 157 | |
154 | OmniAuth Twitter is tested under 1.8.7, 1.9.2, 1.9.3 and Ruby Enterprise Edition. | |
158 | OmniAuth Twitter is tested under 1.9.3, 2.0.0, 2.1.x, 2.2.x, JRuby, and Rubinius. | |
155 | 159 | |
156 | [](http://travis-ci.org/arunagw/omniauth-twitter) | |
160 | ## Contributing | |
158 | 161 | |
159 | ## Note on Patches/Pull Requests | |
160 | ||
161 | - Fork the project. | |
162 | - Make your feature addition or bug fix. | |
163 | - Add tests for it. This is important so I don’t break it in a future version unintentionally. | |
164 | - 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) | |
165 | - Send me a pull request. Bonus points for topic branches. | |
162 | Please read the [contribution guidelines](CONTRIBUTING.md) for some information on how to get started. No contribution is too small. | |
166 | 163 | |
167 | 164 | ## License |
168 | 165 |
0 | 0 | require 'omniauth-oauth' |
1 | require 'multi_json' | |
1 | require 'json' | |
2 | 2 | |
3 | 3 | module OmniAuth |
4 | 4 | module Strategies |
26 | 26 | end |
27 | 27 | |
28 | 28 | extra do |
29 | { :raw_info => raw_info } | |
29 | skip_info? ? {} : { :raw_info => raw_info } | |
30 | 30 | end |
31 | 31 | |
32 | 32 | def raw_info |
33 | @raw_info ||= MultiJson.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body) | |
33 | @raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body) | |
34 | 34 | rescue ::Errno::ETIMEDOUT |
35 | 35 | raise ::Timeout::Error |
36 | 36 | end |
50 | 50 | end |
51 | 51 | end |
52 | 52 | |
53 | if request.params['use_authorize'] == 'true' | |
53 | if options[:use_authorize] || request.params['use_authorize'] == 'true' | |
54 | 54 | options[:client_options][:authorize_path] = '/oauth/authorize' |
55 | 55 | else |
56 | 56 | options[:client_options][:authorize_path] = '/oauth/authenticate' |
0 | 0 | --- !ruby/object:Gem::Specification |
1 | 1 | name: omniauth-twitter |
2 | 2 | version: !ruby/object:Gem::Version |
3 | version: 1.0.1 | |
3 | version: 1.2.0 | |
4 | 4 | platform: ruby |
5 | 5 | authors: |
6 | 6 | - Arun Agrawal |
7 | 7 | autorequire: |
8 | 8 | bindir: bin |
9 | 9 | cert_chain: [] |
10 | date: 2013-10-04 00:00:00.000000000 Z | |
10 | date: 2015-04-22 00:00:00.000000000 Z | |
11 | 11 | dependencies: |
12 | 12 | - !ruby/object:Gem::Dependency |
13 | name: multi_json | |
13 | name: json | |
14 | 14 | requirement: !ruby/object:Gem::Requirement |
15 | 15 | requirements: |
16 | 16 | - - ~> |
29 | 29 | requirements: |
30 | 30 | - - ~> |
31 | 31 | - !ruby/object:Gem::Version |
32 | version: '1.0' | |
32 | version: '1.1' | |
33 | 33 | type: :runtime |
34 | 34 | prerelease: false |
35 | 35 | version_requirements: !ruby/object:Gem::Requirement |
36 | 36 | requirements: |
37 | 37 | - - ~> |
38 | 38 | - !ruby/object:Gem::Version |
39 | version: '1.0' | |
39 | version: '1.1' | |
40 | 40 | - !ruby/object:Gem::Dependency |
41 | name: rspec | |
41 | name: bundler | |
42 | 42 | requirement: !ruby/object:Gem::Requirement |
43 | 43 | requirements: |
44 | 44 | - - ~> |
45 | 45 | - !ruby/object:Gem::Version |
46 | version: '2.7' | |
46 | version: '1.0' | |
47 | 47 | type: :development |
48 | 48 | prerelease: false |
49 | 49 | version_requirements: !ruby/object:Gem::Requirement |
50 | 50 | requirements: |
51 | 51 | - - ~> |
52 | 52 | - !ruby/object:Gem::Version |
53 | version: '2.7' | |
54 | - !ruby/object:Gem::Dependency | |
55 | name: rack-test | |
56 | requirement: !ruby/object:Gem::Requirement | |
57 | requirements: | |
58 | - - '>=' | |
59 | - !ruby/object:Gem::Version | |
60 | version: '0' | |
61 | type: :development | |
62 | prerelease: false | |
63 | version_requirements: !ruby/object:Gem::Requirement | |
64 | requirements: | |
65 | - - '>=' | |
66 | - !ruby/object:Gem::Version | |
67 | version: '0' | |
68 | - !ruby/object:Gem::Dependency | |
69 | name: simplecov | |
70 | requirement: !ruby/object:Gem::Requirement | |
71 | requirements: | |
72 | - - '>=' | |
73 | - !ruby/object:Gem::Version | |
74 | version: '0' | |
75 | type: :development | |
76 | prerelease: false | |
77 | version_requirements: !ruby/object:Gem::Requirement | |
78 | requirements: | |
79 | - - '>=' | |
80 | - !ruby/object:Gem::Version | |
81 | version: '0' | |
82 | - !ruby/object:Gem::Dependency | |
83 | name: webmock | |
84 | requirement: !ruby/object:Gem::Requirement | |
85 | requirements: | |
86 | - - '>=' | |
87 | - !ruby/object:Gem::Version | |
88 | version: '0' | |
89 | type: :development | |
90 | prerelease: false | |
91 | version_requirements: !ruby/object:Gem::Requirement | |
92 | requirements: | |
93 | - - '>=' | |
94 | - !ruby/object:Gem::Version | |
95 | version: '0' | |
53 | version: '1.0' | |
96 | 54 | description: OmniAuth strategy for Twitter |
97 | 55 | email: |
98 | 56 | - arunagw@gmail.com |
103 | 61 | - .gitignore |
104 | 62 | - .rspec |
105 | 63 | - .travis.yml |
64 | - CONTRIBUTING.md | |
106 | 65 | - Gemfile |
107 | 66 | - README.md |
108 | 67 | - Rakefile |
131 | 90 | - !ruby/object:Gem::Version |
132 | 91 | version: '0' |
133 | 92 | requirements: [] |
134 | rubyforge_project: omniauth-twitter | |
135 | rubygems_version: 2.0.6 | |
93 | rubyforge_project: | |
94 | rubygems_version: 2.0.14 | |
136 | 95 | signing_key: |
137 | 96 | specification_version: 4 |
138 | 97 | summary: OmniAuth strategy for Twitter |
7 | 7 | s.authors = ["Arun Agrawal"] |
8 | 8 | s.email = ["arunagw@gmail.com"] |
9 | 9 | s.homepage = "https://github.com/arunagw/omniauth-twitter" |
10 | s.summary = %q{OmniAuth strategy for Twitter} | |
11 | 10 | s.description = %q{OmniAuth strategy for Twitter} |
11 | s.summary = s.description | |
12 | 12 | s.license = "MIT" |
13 | ||
14 | s.rubyforge_project = "omniauth-twitter" | |
15 | 13 | |
16 | 14 | s.files = `git ls-files`.split("\n") |
17 | 15 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") |
18 | 16 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } |
19 | 17 | s.require_paths = ["lib"] |
20 | 18 | |
21 | s.add_dependency 'multi_json', '~> 1.3' | |
22 | s.add_runtime_dependency 'omniauth-oauth', '~> 1.0' | |
23 | s.add_development_dependency 'rspec', '~> 2.7' | |
24 | s.add_development_dependency 'rack-test' | |
25 | s.add_development_dependency 'simplecov' | |
26 | s.add_development_dependency 'webmock' | |
19 | s.add_dependency 'json', '~> 1.3' | |
20 | s.add_dependency 'omniauth-oauth', '~> 1.1' | |
21 | s.add_development_dependency 'bundler', '~> 1.0' | |
27 | 22 | end |
5 | 5 | subject do |
6 | 6 | args = ['appid', 'secret', @options || {}].compact |
7 | 7 | OmniAuth::Strategies::Twitter.new(*args).tap do |strategy| |
8 | strategy.stub(:request) { | |
8 | allow(strategy).to receive(:request) { | |
9 | 9 | request |
10 | 10 | } |
11 | 11 | end |
29 | 29 | context 'when user has an image' do |
30 | 30 | it 'should return image with size specified' do |
31 | 31 | @options = { :image_size => 'original' } |
32 | subject.stub(:raw_info).and_return( | |
32 | allow(subject).to receive(:raw_info).and_return( | |
33 | 33 | { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } |
34 | 34 | ) |
35 | 35 | expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png') |
36 | 36 | end |
37 | 37 | |
38 | it 'should return bigger image when bigger size specified' do | |
39 | @options = { :image_size => 'bigger' } | |
40 | allow(subject).to receive(:raw_info).and_return( | |
41 | { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } | |
42 | ) | |
43 | expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_bigger.png') | |
44 | end | |
45 | ||
38 | 46 | it 'should return secure image with size specified' do |
39 | 47 | @options = { :secure_image_url => 'true', :image_size => 'mini' } |
40 | subject.stub(:raw_info).and_return( | |
48 | allow(subject).to receive(:raw_info).and_return( | |
41 | 49 | { 'profile_image_url_https' => 'https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } |
42 | 50 | ) |
43 | 51 | expect(subject.info[:image]).to eq('https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_mini.png') |
44 | 52 | end |
45 | 53 | |
46 | 54 | it 'should return normal image by default' do |
47 | subject.stub(:raw_info).and_return( | |
55 | allow(subject).to receive(:raw_info).and_return( | |
48 | 56 | { 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' } |
49 | 57 | ) |
50 | 58 | expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png') |
52 | 60 | end |
53 | 61 | end |
54 | 62 | |
63 | describe 'skip_info option' do | |
64 | context 'when skip info option is enabled' do | |
65 | it 'should not include raw_info in extras hash' do | |
66 | @options = { :skip_info => true } | |
67 | allow(subject).to receive(:raw_info).and_return({:foo => 'bar'}) | |
68 | expect(subject.extra[:raw_info]).to eq(nil) | |
69 | end | |
70 | end | |
71 | end | |
72 | ||
55 | 73 | describe 'request_phase' do |
56 | 74 | context 'with no request params set and x_auth_access_type specified' do |
57 | 75 | before do |
58 | subject.stub(:request).and_return( | |
76 | allow(subject).to receive(:request).and_return( | |
59 | 77 | double('Request', {:params => {'x_auth_access_type' => 'read'}}) |
60 | 78 | ) |
61 | subject.stub(:old_request_phase).and_return(:whatever) | |
79 | allow(subject).to receive(:old_request_phase).and_return(:whatever) | |
62 | 80 | end |
63 | 81 | |
64 | 82 | it 'should not break' do |
65 | 83 | expect { subject.request_phase }.not_to raise_error |
66 | 84 | end |
67 | 85 | end |
86 | ||
87 | context "with no request params set and use_authorize options provided" do | |
88 | before do | |
89 | @options = { :use_authorize => true } | |
90 | allow(subject).to receive(:request) do | |
91 | double('Request', {:params => {} }) | |
92 | end | |
93 | allow(subject).to receive(:old_request_phase) { :whatever } | |
94 | end | |
95 | ||
96 | it "should switch authorize_path from authenticate to authorize" do | |
97 | expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize') | |
98 | end | |
99 | end | |
100 | ||
101 | context "with no request params set and force_login specified" do | |
102 | before do | |
103 | allow(subject).to receive(:request) do | |
104 | double('Request', {:params => { 'force_login' => true } }) | |
105 | end | |
106 | allow(subject).to receive(:old_request_phase) { :whatever } | |
107 | end | |
108 | ||
109 | it "should change add force_login=true to authorize_params" do | |
110 | expect { subject.request_phase }.to change {subject.options.authorize_params.force_login}.from(nil).to(true) | |
111 | end | |
112 | end | |
68 | 113 | end |
69 | 114 | end |