Class: OmniAuth::Strategies::Twitter
- Defined in:
- lib/omniauth/strategies/oauth/twitter.rb
Overview
Authenticate to Twitter via OAuth and retrieve basic user information.
Usage: use OmniAuth::Strategies::Twitter, 'consumerkey', 'consumersecret'
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Twitter
constructor
Initialize the middleware.
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Twitter
Initialize the middleware
15 16 17 18 19 20 21 22 |
# File 'lib/omniauth/strategies/oauth/twitter.rb', line 15 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) = { :site => 'https://api.twitter.com', } [:authorize_params] = {:force_login => 'true'} if .delete(:force_login) == true [:authorize_path] = '/oauth/authenticate' unless [:sign_in] == false super(app, [:name] || :twitter, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/omniauth/strategies/oauth/twitter.rb', line 24 def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => @access_token.params[:user_id], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash, }, } ) end |
#user_hash ⇒ Object
51 52 53 54 55 |
# File 'lib/omniauth/strategies/oauth/twitter.rb', line 51 def user_hash @user_hash ||= MultiJson.decode(@access_token.get('/1/account/verify_credentials.json').body) rescue ::Errno::ETIMEDOUT raise ::Timeout::Error end |
#user_info ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/omniauth/strategies/oauth/twitter.rb', line 36 def user_info user_hash = self.user_hash { 'nickname' => user_hash['screen_name'], 'name' => user_hash['name'] || user_hash['screen_name'], 'location' => user_hash['location'], 'image' => user_hash['profile_image_url'], 'description' => user_hash['description'], 'urls' => { 'Website' => user_hash['url'], 'Twitter' => 'http://twitter.com/' + user_hash['screen_name'], }, } end |