Codebase list ruby-omniauth-twitter / 1a3213f
Imported Upstream version 0.0.16 Praveen Arimbrathodiyil 10 years ago
13 changed file(s) with 414 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 *.gem
1 .bundle
2 Gemfile.lock
3 pkg/*
4 coverage
0 --colour
0 rvm:
1 - 1.8.7
2 - 1.9.2
3 - 1.9.3
4 - ree
5 - jruby
0 source "https://rubygems.org"
1
2 gem 'rake'
3 # Specify your gem's dependencies in omniauth-twitter.gemspec
4 gemspec
0 # OmniAuth Twitter
1
2 This gem contains the Twitter strategy for OmniAuth.
3
4 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
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.
7
8 ## Before You Begin
9
10 You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
11
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.)
13
14 ## Using This Strategy
15
16 First start by adding this gem to your Gemfile:
17
18 gem 'omniauth-twitter'
19
20 If you need to use the latest HEAD version, you can do so with:
21
22 gem 'omniauth-twitter', :github => 'arunagw/omniauth-twitter'
23
24 Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
25
26 Rails.application.config.middleware.use OmniAuth::Builder do
27 provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET"
28 end
29
30 Replace CONSUMER_KEY and CONSUMER_SECRET with the appropriate values you obtained from dev.twitter.com earlier.
31
32 ## Authentication Options
33
34 Twitter supports a [few options](https://dev.twitter.com/docs/api/1/get/oauth/authenticate) when authenticating. Usually you would specify these options as query parameters to the Twitter API authentication url (`https://api.twitter.com/oauth/authenticate` by default). With OmniAuth, of course, you use `http://yourapp.com/auth/twitter` instead. Because of this, this OmniAuth provider will pick up the query parameters you pass to the `/auth/twitter` URL and re-use them when making the call to the Twitter API.
35
36 The options are:
37
38 * **force_login** - This option sends the user to a sign-in screen to enter their Twitter credentials, even if they are already signed in. This is handy when your application supports multiple Twitter accounts and you want to ensure the correct user is signed in. *Example:* `http://yoursite.com/auth/twitter?force_login=true`
39
40 * **screen_name** - This option implies **force_login**, except the screen name field is pre-filled with a particular value. *Example:* `http://yoursite.com/auth/twitter?screen_name=jim`
41
42 * **x_auth_access_type** - This option (described [here](https://dev.twitter.com/docs/api/1/post/oauth/request_token)) lets you request the level of access that your app will have to the Twitter account in question. *Example:* `http://yoursite.com/auth/twitter?x_auth_access_type=read`
43
44 * **use_authorize** - There are actually two URLs you can use against the Twitter API. As mentioned, the default is `https://api.twitter.com/oauth/authenticate`, but you also have `https://api.twitter.com/oauth/authorize`. Passing this option as `true` will use the second URL rather than the first. What's the difference? As described [here](https://dev.twitter.com/docs/api/1/get/oauth/authenticate), with `authenticate`, if your user has already granted permission to your application, Twitter will redirect straight back to your application, whereas `authorize` forces the user to go through the "grant permission" screen again. For certain use cases this may be necessary. *Example:* `http://yoursite.com/auth/twitter?use_authorize=true`
45
46 ## Watch the RailsCast
47
48 Ryan Bates has put together an excellent RailsCast on OmniAuth:
49
50 [![RailsCast #241](https://www.evernote.com/shard/s35/sh/479f2503-aefa-4542-a7b4-8f84fd22eafc/0571f5a3795a0be3d0b0814312a8d5b7/res/49b5478a-657c-4aff-ae58-dae08b9a46d5/Screen_Shot_2012-07-15_at_12.41.15_PM-20120715-125424.jpg "RailsCast #241 - Simple OmniAuth (revised)")](http://railscasts.com/episodes/241-simple-omniauth-revised)
51
52 ## Supported Rubies
53
54 OmniAuth Twitter is tested under 1.8.7, 1.9.2, 1.9.3 and Ruby Enterprise Edition.
55
56 [![CI Build
57 Status](https://secure.travis-ci.org/arunagw/omniauth-twitter.png)](http://travis-ci.org/arunagw/omniauth-twitter)
58
59 ## Note on Patches/Pull Requests
60
61 - Fork the project.
62 - Make your feature addition or bug fix.
63 - Add tests for it. This is important so I don’t break it in a future version unintentionally.
64 - 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)
65 - Send me a pull request. Bonus points for topic branches.
66
67 ## License
68
69 Copyright (c) 2011 by Arun Agrawal
70
71 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
72
73 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
74
75 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.
0 require "bundler/gem_tasks"
1 require 'rspec/core/rake_task'
2
3 desc "Run specs"
4 RSpec::Core::RakeTask.new
5
6 desc 'Default: run specs.'
7 task :default => :spec
0 require 'omniauth-oauth'
1 require 'multi_json'
2
3 module OmniAuth
4 module Strategies
5 class Twitter < OmniAuth::Strategies::OAuth
6 option :name, 'twitter'
7 option :client_options, {:authorize_path => '/oauth/authenticate',
8 :site => 'https://api.twitter.com',
9 :proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil}
10
11 uid { access_token.params[:user_id] }
12
13 info do
14 {
15 :nickname => raw_info['screen_name'],
16 :name => raw_info['name'],
17 :location => raw_info['location'],
18 :image => options[:secure_image_url] ? raw_info['profile_image_url_https'] : raw_info['profile_image_url'],
19 :description => raw_info['description'],
20 :urls => {
21 'Website' => raw_info['url'],
22 'Twitter' => "https://twitter.com/#{raw_info['screen_name']}",
23 }
24 }
25 end
26
27 extra do
28 { :raw_info => raw_info }
29 end
30
31 def raw_info
32 @raw_info ||= MultiJson.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body)
33 rescue ::Errno::ETIMEDOUT
34 raise ::Timeout::Error
35 end
36
37 alias :old_request_phase :request_phase
38
39 def request_phase
40 force_login = session['omniauth.params'] ? session['omniauth.params']['force_login'] : nil
41 screen_name = session['omniauth.params'] ? session['omniauth.params']['screen_name'] : nil
42 x_auth_access_type = session['omniauth.params'] ? session['omniauth.params']['x_auth_access_type'] : nil
43 if force_login && !force_login.empty?
44 options[:authorize_params] ||= {}
45 options[:authorize_params].merge!(:force_login => 'true')
46 end
47 if screen_name && !screen_name.empty?
48 options[:authorize_params] ||= {}
49 options[:authorize_params].merge!(:force_login => 'true', :screen_name => screen_name)
50 end
51 if x_auth_access_type
52 options[:request_params] ||= {}
53 options[:request_params].merge!(:x_auth_access_type => x_auth_access_type)
54 end
55
56 if session['omniauth.params'] && session['omniauth.params']["use_authorize"] == "true"
57 options.client_options.authorize_path = '/oauth/authorize'
58 else
59 options.client_options.authorize_path = '/oauth/authenticate'
60 end
61
62 old_request_phase
63 end
64
65 end
66 end
67 end
0 module OmniAuth
1 module Twitter
2 VERSION = "0.0.16"
3 end
4 end
0 require "omniauth-twitter/version"
1 require 'omniauth/strategies/twitter'
0 --- !ruby/object:Gem::Specification
1 name: omniauth-twitter
2 version: !ruby/object:Gem::Version
3 version: 0.0.16
4 prerelease:
5 platform: ruby
6 authors:
7 - Arun Agrawal
8 autorequire:
9 bindir: bin
10 cert_chain: []
11 date: 2013-04-03 00:00:00.000000000 Z
12 dependencies:
13 - !ruby/object:Gem::Dependency
14 name: multi_json
15 requirement: !ruby/object:Gem::Requirement
16 none: false
17 requirements:
18 - - ~>
19 - !ruby/object:Gem::Version
20 version: '1.3'
21 type: :runtime
22 prerelease: false
23 version_requirements: !ruby/object:Gem::Requirement
24 none: false
25 requirements:
26 - - ~>
27 - !ruby/object:Gem::Version
28 version: '1.3'
29 - !ruby/object:Gem::Dependency
30 name: omniauth-oauth
31 requirement: !ruby/object:Gem::Requirement
32 none: false
33 requirements:
34 - - ~>
35 - !ruby/object:Gem::Version
36 version: '1.0'
37 type: :runtime
38 prerelease: false
39 version_requirements: !ruby/object:Gem::Requirement
40 none: false
41 requirements:
42 - - ~>
43 - !ruby/object:Gem::Version
44 version: '1.0'
45 - !ruby/object:Gem::Dependency
46 name: rspec
47 requirement: !ruby/object:Gem::Requirement
48 none: false
49 requirements:
50 - - ~>
51 - !ruby/object:Gem::Version
52 version: '2.7'
53 type: :development
54 prerelease: false
55 version_requirements: !ruby/object:Gem::Requirement
56 none: false
57 requirements:
58 - - ~>
59 - !ruby/object:Gem::Version
60 version: '2.7'
61 - !ruby/object:Gem::Dependency
62 name: rack-test
63 requirement: !ruby/object:Gem::Requirement
64 none: false
65 requirements:
66 - - ! '>='
67 - !ruby/object:Gem::Version
68 version: '0'
69 type: :development
70 prerelease: false
71 version_requirements: !ruby/object:Gem::Requirement
72 none: false
73 requirements:
74 - - ! '>='
75 - !ruby/object:Gem::Version
76 version: '0'
77 - !ruby/object:Gem::Dependency
78 name: simplecov
79 requirement: !ruby/object:Gem::Requirement
80 none: false
81 requirements:
82 - - ! '>='
83 - !ruby/object:Gem::Version
84 version: '0'
85 type: :development
86 prerelease: false
87 version_requirements: !ruby/object:Gem::Requirement
88 none: false
89 requirements:
90 - - ! '>='
91 - !ruby/object:Gem::Version
92 version: '0'
93 - !ruby/object:Gem::Dependency
94 name: webmock
95 requirement: !ruby/object:Gem::Requirement
96 none: false
97 requirements:
98 - - ! '>='
99 - !ruby/object:Gem::Version
100 version: '0'
101 type: :development
102 prerelease: false
103 version_requirements: !ruby/object:Gem::Requirement
104 none: false
105 requirements:
106 - - ! '>='
107 - !ruby/object:Gem::Version
108 version: '0'
109 description: OmniAuth strategy for Twitter
110 email:
111 - arunagw@gmail.com
112 executables: []
113 extensions: []
114 extra_rdoc_files: []
115 files:
116 - .gitignore
117 - .rspec
118 - .travis.yml
119 - Gemfile
120 - README.md
121 - Rakefile
122 - lib/omniauth-twitter.rb
123 - lib/omniauth-twitter/version.rb
124 - lib/omniauth/strategies/twitter.rb
125 - omniauth-twitter.gemspec
126 - spec/omniauth/strategies/twitter_spec.rb
127 - spec/spec_helper.rb
128 homepage: https://github.com/arunagw/omniauth-twitter
129 licenses:
130 - MIT
131 post_install_message:
132 rdoc_options: []
133 require_paths:
134 - lib
135 required_ruby_version: !ruby/object:Gem::Requirement
136 none: false
137 requirements:
138 - - ! '>='
139 - !ruby/object:Gem::Version
140 version: '0'
141 required_rubygems_version: !ruby/object:Gem::Requirement
142 none: false
143 requirements:
144 - - ! '>='
145 - !ruby/object:Gem::Version
146 version: '0'
147 requirements: []
148 rubyforge_project: omniauth-twitter
149 rubygems_version: 1.8.25
150 signing_key:
151 specification_version: 3
152 summary: OmniAuth strategy for Twitter
153 test_files:
154 - spec/omniauth/strategies/twitter_spec.rb
155 - spec/spec_helper.rb
0 # -*- encoding: utf-8 -*-
1 $:.push File.expand_path("../lib", __FILE__)
2 require "omniauth-twitter/version"
3
4 Gem::Specification.new do |s|
5 s.name = "omniauth-twitter"
6 s.version = OmniAuth::Twitter::VERSION
7 s.authors = ["Arun Agrawal"]
8 s.email = ["arunagw@gmail.com"]
9 s.homepage = "https://github.com/arunagw/omniauth-twitter"
10 s.summary = %q{OmniAuth strategy for Twitter}
11 s.description = %q{OmniAuth strategy for Twitter}
12 s.license = "MIT"
13
14 s.rubyforge_project = "omniauth-twitter"
15
16 s.files = `git ls-files`.split("\n")
17 s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18 s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19 s.require_paths = ["lib"]
20
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'
27 end
0 require 'spec_helper'
1
2 describe OmniAuth::Strategies::Twitter do
3 subject do
4 OmniAuth::Strategies::Twitter.new({})
5 end
6
7 context 'client options' do
8 it 'should have correct name' do
9 expect(subject.options.name).to eq('twitter')
10 end
11
12 it 'should have correct site' do
13 expect(subject.options.client_options.site).to eq('https://api.twitter.com')
14 end
15
16 it 'should have correct authorize url' do
17 expect(subject.options.client_options.authorize_path).to eq('/oauth/authenticate')
18 end
19 end
20
21 describe 'request_phase' do
22 context 'no request params set and x_auth_access_type specified' do
23 before do
24 subject.options[:request_params] = nil
25 subject.stub(:session).and_return(
26 {'omniauth.params' => {'x_auth_access_type' => 'read'}})
27 subject.stub(:old_request_phase).and_return(:whatever)
28 end
29
30 it 'should not break' do
31 expect { subject.request_phase }.not_to raise_error
32 end
33 end
34 end
35 end
0 $:.unshift File.expand_path('..', __FILE__)
1 $:.unshift File.expand_path('../../lib', __FILE__)
2 require 'simplecov'
3 SimpleCov.start
4 require 'rspec'
5 require 'rack/test'
6 require 'webmock/rspec'
7 require 'omniauth'
8 require 'omniauth-twitter'
9
10 RSpec.configure do |config|
11 config.include WebMock::API
12 config.include Rack::Test::Methods
13 config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
14 config.expect_with :rspec do |c|
15 c.syntax = :expect
16 end
17 end