Git Product home page Git Product logo

omniauth-twitter's Introduction

OmniAuth Twitter

Gem Version Code Climate

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" flow.

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 to get started.

Now sign in into the Twitter developer area 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

First start by adding this gem to your Gemfile:

gem 'omniauth-twitter'

If you need to use the latest HEAD version, you can do so with:

gem 'omniauth-twitter', :github => 'arunagw/omniauth-twitter'

Next, tell OmniAuth about this provider. For a Rails app, your config/initializers/omniauth.rb file should look like this:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, "API_KEY", "API_SECRET"
end

Replace "API_KEY" and "API_SECRET" with the appropriate values you obtained earlier.

Authentication Options

Twitter supports a few options 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.

The options are:

  • 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

  • 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

  • lang - The language used in the Twitter prompt. This is useful for adding i18n support since the language of the prompt can be dynamically set for each user. Example: http://yoursite.com/auth/twitter?lang=pt

  • secure_image_url - Set to true to use https for the user's image URL. Default is false.

  • image_size: This option defines the size of the user's image. Valid options include mini (24x24), normal (48x48), bigger (73x73) and original (the size of the image originally uploaded). Default is normal.

  • x_auth_access_type - This option (described here) 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

  • 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, 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. Note: You must have "Allow this application to be used to Sign in with Twitter" checked in your application's settings - without it your user will be asked to authorize your application each time they log in.

Here's an example of a possible configuration where the user's original profile picture is returned over https, the user is always prompted to sign-in and the default language of the Twitter prompt is changed:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, "API_KEY", "API_SECRET",
    {
      :secure_image_url => 'true',
      :image_size => 'original',
      :authorize_params => {
        :force_login => 'true',
        :lang => 'pt'
      }
    }
end

Authentication Hash

An example auth hash available in request.env['omniauth.auth']:

{
  :provider => "twitter",
  :uid => "123456",
  :info => {
    :nickname => "johnqpublic", # screen name
    :name => "John Q Public",
    :location => "Anytown, USA",
    :image => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
    :description => "a very normal guy.",
    :urls => {
      :Website => nil,
      :Twitter => "https://twitter.com/johnqpublic"
    }
  },
  :credentials => {
    :token => "a1b2c3d4...", # The OAuth 2.0 access token
    :secret => "abcdef1234"
  },
  :extra => {
    :access_token => "", # An OAuth::AccessToken object
    :raw_info => {
      :name => "John Q Public",
      :listed_count => 0,
      :profile_sidebar_border_color => "181A1E",
      :url => nil,
      :lang => "en",
      :statuses_count => 129,
      :profile_image_url => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      :profile_background_image_url_https => "https://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
      :location => "Anytown, USA",
      :time_zone => "Chicago",
      :follow_request_sent => false,
      :id => 123456,
      :profile_background_tile => true,
      :profile_sidebar_fill_color => "666666",
      :followers_count => 1,
      :default_profile_image => false,
      :screen_name => "johnqpublic",
      :following => false,
      :utc_offset => -3600,
      :verified => false,
      :favourites_count => 0,
      :profile_background_color => "1A1B1F",
      :is_translator => false,
      :friends_count => 1,
      :notifications => false,
      :geo_enabled => true,
      :profile_background_image_url => "http://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
      :protected => false,
      :description => "a very normal guy.",
      :profile_link_color => "2FC2EF",
      :created_at => "Thu Jul 4 00:00:00 +0000 2013",
      :id_str => "123456",
      :profile_image_url_https => "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
      :default_profile => false,
      :profile_use_background_image => false,
      :entities => {
        :description => {
          :urls => []
        }
      },
      :profile_text_color => "666666",
      :contributors_enabled => false
    }
  }
}

Watch the RailsCast

Ryan Bates has put together an excellent RailsCast on OmniAuth:

RailsCast #241

Supported Rubies

OmniAuth Twitter is tested under 2.1.x, 2.2.x and JRuby.

If you use its gem on ruby 1.9.x, 2.0.x, or Rubinius use version v1.2.1 .

Contributing

Please read the contribution guidelines for some information on how to get started. No contribution is too small.

License

Copyright (c) 2011 by Arun Agrawal

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:

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.

omniauth-twitter's People

Contributors

aaronpk avatar agis avatar alanho avatar amatsuda avatar anildigital avatar arunagw avatar brightchimp avatar bzf avatar cllns avatar excid3 avatar finist avatar fosrias avatar gmccue avatar guilhermesimoes avatar jessieay avatar joona avatar jordimassaguerpla avatar kevinrobinson avatar loganhasson avatar mattgoldman avatar mcmire avatar michaelrbock avatar nchelluri avatar nicolasleger avatar raysrashmi avatar rdsoze avatar rocky-jaiswal avatar scottwater avatar sferik avatar unasuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

omniauth-twitter's Issues

OAuth::Unauthorized (400 Bad Request)

I'm getting this error in Development. Is there a problem with setting 0.0.0.0:3000 as the domain of the callback?

This is what I'm getting

OAuth::Unauthorized (400 Bad Request):
oauth (0.5.1) lib/oauth/consumer.rb:217:in token_request' oauth (0.5.1) lib/oauth/consumer.rb:136:inget_request_token'
omniauth-oauth (1.1.0) lib/omniauth/strategies/oauth.rb:28:in request_phase' omniauth-twitter (1.2.1) lib/omniauth/strategies/twitter.rb:61:inrequest_phase'
omniauth (1.3.1) lib/omniauth/strategy.rb:215:in request_call' omniauth (1.3.1) lib/omniauth/strategy.rb:183:incall!'

My devise.rb has this line:

config.omniauth :twitter, setup: true

And in the setup method, in a controller, I have these lines

env['omniauth.strategy'].options[:client_id] = id
env['omniauth.strategy'].options[:client_secret] = token

The variables "id" and "token" correctly matches my Twitter application's credentials.

What could be the problem?

TypeError: can't convert nil into String

Seeing these errors at random in production. Any idea what that could be?

vendor/bundle/ruby/1.9.1/gems/omniauth-twitter-0.0.9/lib/omniauth/strategies/twitter.rb:22:in `+'
vendor/bundle/ruby/1.9.1/gems/omniauth-twitter-0.0.9/lib/omniauth/strategies/twitter.rb:22:in `block in <class:Twitter>'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:102:in `instance_eval'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:102:in `block in compile_stack'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:101:in `each'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:101:in `inject'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:101:in `compile_stack'
(eval):7:in `info_stack'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:313:in `info'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:326:in `auth_hash'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:353:in `callback_phase'
vendor/bundle/ruby/1.9.1/gems/omniauth-oauth-1.0.1/lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:219:in `callback_call'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:175:in `call!'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/strategy.rb:157:in `call'
vendor/bundle/ruby/1.9.1/gems/omniauth-1.1.0/lib/omniauth/builder.rb:48:in `call'

Session expired

I'm having lots of failing authentications. Lots of requests are redirected to /auth/failure?message=session_expired. The strange part is that waiting a couple of minutes and trying again works most of the times.

How can I debug or even fix this problem?

Thanks a lot!

Image Size not Respected

I'm trying to grab the original large size image, but it's returning the normal size anyway. Any recommendations?

My omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do

  provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'],
    {
      secure_image_url: 'true',
      image_size: 'original',
      authorize_params: {
        force_login: 'false',
        lang: 'en'
      }
    }
end

Not getting Email in auth raw_info

I want to get the email address as well when I ask the user to sign in with Twitter.

I see the latest commit being related to that. But it's not been released. As of now 1.2.0 is the latest gem from April 22 and this commit is more recent.

I would like to request you to release the latest version with the email support for twitter.

OAuth::Unauthorized (401 Unauthorized)

I'm getting the oauth unauthorized error during callback,
I did a lot of googling but couldn't fix it :(

I tried changing the callback url but didn't work
i currently have the call back url as 127.0.0.1:3000/auth/twitter/callback

Always authorizing

I'm using devise + omniauth + omniauth-twitter, and the user is always prompted with the "authorize app" window, and the URL accessed is https://api.twitter.com/oauth/authorize.

I've tried numerous ways to change this to authenticate (which I believe should be the default), with no success.

Any help?

NoMethodError: undefined method `sub' for nil:NilClass

Using omniauth-twitter (1.2.1) with sinatra (on Heroku), we get the following stacktrace once in a while:

/gems/omniauth-twitter-1.2.1/lib/omniauth/strategies/twitter.rb:74 in image_url
/gems/omniauth-twitter-1.2.1/lib/omniauth/strategies/twitter.rb:21 in block in <class:Twitter>
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:105 in instance_eval
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:105 in block in compile_stack
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:104 in each
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:104 in inject
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:104 in compile_stack
(eval):7 in info_stack
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:321 in info
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:334 in auth_hash
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:361 in callback_phase
/gems/omniauth-oauth-1.1.0/lib/omniauth/strategies/oauth.rb:57 in callback_phase
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:227 in callback_call
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:184 in call!
/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:164 in call
/gems/omniauth-1.2.2/lib/omniauth/builder.rb:59 in call
/app/lib/platform/rack/caching.rb:26 in call
/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225 in context
/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220 in call
/gems/rack-timeout-0.2.4/lib/rack/timeout.rb:108 in call
/gems/rack-rewrite-1.5.1/lib/rack/rewrite.rb:24 in call
/gems/rack-ssl-enforcer-0.2.9/lib/rack/ssl-enforcer.rb:52 in call

Seems that we have users that haven't set their twitter image (original_url) - and that the info compilation fails because of that.

Let me know if you need more! Would be glad to help eliminating this.

Cannot allocate memory - /usr/lib/ruby/1.8/x86_64-linux/nkf.so

I am trying to load a rails 3.1 app on Passenger (dreamhost) and I get the following error

Error message:
/usr/lib/ruby/1.8/x86_64-linux/nkf.so: failed to map segment from shared object: Cannot allocate memory - /usr/lib/ruby/1.8/x86_64-linux/nkf.so

Backtrace:

File
Line
Location
0
/usr/lib/ruby/1.8/x86_64-linux/nkf.so

1
/usr/lib/ruby/1.8/kconv.rb
12

2
/usr/lib/ruby/1.8/base64.rb
14
in `require'
3
/usr/lib/ruby/1.8/base64.rb
14

4
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/helper.rb
2
in `require'
5
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/helper.rb
2

6
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/client/net_http.rb
1
in `require'
7
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/client/net_http.rb
1

8
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/consumer.rb
4
in `require'
9
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/consumer.rb
4

10
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/client/helper.rb
2
in `require'
11
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth/client/helper.rb
2

12
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth.rb
10
in `require'
13
/home/USERNAME/.gems/gems/oauth-0.4.5/lib/oauth.rb
10

14
/home/USERNAME/.gems/gems/omniauth-oauth-1.0.0/lib/omniauth/strategies/oauth.rb
2
in `require'
15
/home/USERNAME/.gems/gems/omniauth-oauth-1.0.0/lib/omniauth/strategies/oauth.rb
2

16
/home/USERNAME/.gems/gems/omniauth-oauth-1.0.0/lib/omniauth-oauth.rb
2
in `require'
17
/home/USERNAME/.gems/gems/omniauth-oauth-1.0.0/lib/omniauth-oauth.rb
2

18
/home/USERNAME/.gems/gems/omniauth-twitter-0.0.6/lib/omniauth/strategies/twitter.rb
1
in `require'
19
/home/USERNAME/.gems/gems/omniauth-twitter-0.0.6/lib/omniauth/strategies/twitter.rb
1

20
/home/USERNAME/.gems/gems/omniauth-twitter-0.0.6/lib/omniauth-twitter.rb
2
in `require'
21
/home/USERNAME/.gems/gems/omniauth-twitter-0.0.6/lib/omniauth-twitter.rb
2

22
/home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb
68
in require' 23 /home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb 68 inrequire'
24
/home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb
66
in each' 25 /home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb 66 inrequire'
26
/home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb
55
in each' 27 /home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler/runtime.rb 55 inrequire'
28
/home/USERNAME/.gems/gems/bundler-1.0.21/lib/bundler.rb
122
in `require'
29
/home/USERNAME/zap.tl/config/application.rb
7

30
/usr/lib/ruby/1.8/rubygems/custom_require.rb
31
in gem_original_require' 31 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 inrequire'
32
/home/USERNAME/zap.tl/config/environment.rb
5

33
/usr/lib/ruby/1.8/rubygems/custom_require.rb
31
in gem_original_require' 34 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 inrequire'
35
config.ru
9

36
/home/USERNAME/.gems/gems/rack-1.3.5/lib/rack/builder.rb
51
in instance_eval' 37 /home/USERNAME/.gems/gems/rack-1.3.5/lib/rack/builder.rb 51 ininitialize'
38
config.ru
1
in `new'
39
config.ru

raw_info values in provider auth is nil

We get the provider auth and store it in the db. Some users have reported a issue that their page is not rendering properly. When we inspected the values in the db for one such user, it was this

:twitterAuth=>"{"twitterId":"XXX","twitterAccessToken":"XXX","twitterAccessTokenSecret":"XXX","twitterScreenName":null,"twitterDescription":null,"twitterFollowersCount":null,"twitterFriendsCount":null,"twitterListedCount":null,"twitterLocation":null,"twitterName":null,"twitterProfileImageUrl":null,"twitterProfileImageUrlHttps":null,"twitterUrl":null,"twitterStatusesCount":null,"twitterUtcOffset":null,"isProtected":null,"isTwitterVerified":null}"

This happens very rarely and there is no pattern to it.

Need email id from twitter via twitter login

@arunagw I want email id of the twitter to store into my application while login via twitter in my app. Can you tell me, how can i able to get the email. I did t see email id of the user from the twitter response after login into my app.

Issue with twitter OAuth Callback

When I try to include the latest Omniauth and Omniauth-twitter get in my app, OAuth Callback gives the following error .
What I see is does sent a UID back which means the twitter auth is successful but it is giving invalid response and looking for the failure url.

Started GET "/auth/twitter/callback?oauth_token=sYeZBEHkthC1Zl4OZpbBlk9BgtkLOJgLsSASrkff2c&oauth_verifier=gOHr1nlKeNhGycIQnoDvvFt3k20c37m3vlrrlsl8U" for 127.0.0.1 at 2011-11-18 16:46:37 +0530
Processing by SessionsController#create as HTML
Parameters: {"oauth_token"=>"sYeZBEHkthC1Zl4OZpbBlk9BgtkLOJgLsSASrkff2c", "oauth_verifier"=>"gOHr1nlKeNhGycIQnoDvvFt3k20c37m3vlrrlsl8U", "provider"=>"twitter"}

Authorization Load (0.2ms) SELECT "authorizations".* FROM "authorizations" WHERE "authorizations"."provider" = 'twitter' AND "authorizations"."uid" = '16867223' LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Completed 500 Internal Server Error in 231ms

Started GET "/auth/failure?message=invalid_response" for 127.0.0.1 at 2011-11-18 16:46:41 +0530

Receiving OAuth::Unauthorized 401 Authorization Required

I've set up a very simple rails app and am unable to get the request to twitter to succeed. It's unclear what the cause is. The key and secret are being ready properly from the environment variables. Twitter no longer allows setting of localhost nor 127.0.0.1 in their callback url. Instead, they state:

Where should we return after successfully authenticating? OAuth 1.0a applications should explicitly specify their oauth_callback URL on the request token step, regardless of the value given here. To restrict your application from using callbacks, leave this field blank.

However, I have not been able to figure out where I am supposed to be passing this information when generating the request.

Here is the code I have written in the initializer. Help would be appreciated.

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer unless Rails.env.production?
  provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
end

Twitter authentication/login issue: "There is no request token for this page..."

Does anyone know how to fix this issue? I keep on getting this error from Twitter when I try to login on our app. This was happening since May 23, 2013 and just for random Twitter accounts.

"Whoa there! The request token for this page is invalid. It may have already been used, or expired because it is too old. Please go back to the site or application that sent you here and try again; it was probably just a mistake."

I also saw some users experiencing this issue in this link: https://dev.twitter.com/discussions/17911 but it seems that Twitter devs haven't got back for a solution.

Hopefully someone can help me with this matter. Thanks a lot!

Twitter giving a "Woah there!" response

Trying to use omniauth 1.0 for the first time.

Added the omniauth and omniauth-twitter gems.

Have an initializer that sets up the twitter provider:

provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']

and the key and secret are being provided via ENV.

I then call /auth/twitter

This takes me to

https://api.twitter.com/oauth/authorize?response_type=code&client_id=<TWITTER_KEY>&redirect_uri=http%3A%2F%2F127.0.0.1%3A3000%2Fauth%2Ftwitter%2Fcallback

But twitter gives me a

Woah there!

This page requires some information that was not provided. Please return to the site that sent you to this page and try again … it was probably an honest mistake.

This key/secret worked fine under the older (pre 1.0) omniauth setup.

I may well have done something wrong - but could really do with a hint as to what ;)

timeout: Timeout::Error, execution expired

I can't implement omniauth-twitter in my app. I get following error:

 Started GET "/auth/twitter" for 127.0.0.1 at 2012-12-01 13:29:23 +0330
 (twitter) Request phase initiated.
 (twitter) Authentication failure! timeout: Timeout::Error, execution expired

Timeout::Error (execution expired):
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `open'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `connect'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:744:in `start'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/net/http.rb:1284:in `request'
  oauth (0.4.6) lib/oauth/consumer.rb:161:in `request'
  oauth (0.4.6) lib/oauth/consumer.rb:194:in `token_request'
  oauth (0.4.6) lib/oauth/consumer.rb:136:in `get_request_token'
  omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
  omniauth-twitter (0.0.11) lib/omniauth/strategies/twitter.rb:50:in `request_phase'
  omniauth (1.1.0) lib/omniauth/strategy.rb:207:in `request_call'
  omniauth (1.1.0) lib/omniauth/strategy.rb:174:in `call!'
  omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
  omniauth (1.1.0) lib/omniauth/builder.rb:48:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__1553044154901315329__call__344883622791553659__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /home/arashm/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

I tried codes from Ryan Bates's railscast reposity but it failed again with the same error.

my app is configured for Twitter like this:

website: 127.0.0.1
callback url: 127.0.0.1:3000/auth/twitter/callback

Error when trying to sign in with suspended account

in lib/omniauth/strategies/twitter.rb

:urls => {
  'Website' => raw_info['url'],
  'Twitter' => 'http://twitter.com/' + raw_info['screen_name'],
}

raw_info['screen_name'] appears to be nil for suspended account, therefore everything breaks.

include force_login parameter

I noticed the ?screen_name addition, but I'd also like to request the ability to set a standalone force_login parameter that does not depend on setting a non-blank screen_name. Ideally this could be set it in the initialzer.

Thanks!

Profile picture disappear after change

Hi,

I have an app that gets on register the auth.info.image and returns the url and add that as their profile picture. I noticed that once a user changes their image on twitter it no longer appears on my app.

Is this because I did not use this auth.extra.raw_info.profile_image_url_https? Instead.

Any information would be very much appreciated.

Verify user from mobile return access token

Hi everyone. I have a problem and it take me so much time :(
I am building Api for mobile app call. And in mobile user login twitter then call back to my server an access_token. So from this access_token, How could I call to get uid, email, username, ... Is this supported in GEM?

Please help me

Not getting nicknames

I seem to be getting nothing returned for user nicknames for most of my users. I am checking the request.env['omniauth.auth']['info']['nickname'] variable and saving it as their username.

I have a check in place to make sure it isn't returning nil and if it does, to save the ['name'] in place of the ['nickname'], but an empty string is getting saved, implying that some users' nicknames are returning as empty strings.

Has anyone else ran into this?

401 Unauthorized

Hi,

I have a twitter app using your gem.

I use heroku to host and was able to signin until last week. This week, I receive an error both locally and in production stating

401 Unauthorized

I did not change anything and have tried to play with the callback url by leaving it empty and with an address to no avail.

Can you please advise on what could be the issue.

Deepak

session[:oauth] remains after callback

I'm not sure if this is a bug or a feature :)

After a successful authentication with omniauth-twitter, session[:oauth] contains:

{
  "twitter" => {
    "callback_confirmed" => true
  }
}

This is because omniauth-oauth does this in request_phase

session['oauth'][name.to_s] = {
  'callback_confirmed' => request_token.callback_confirmed?,
  'request_token' => request_token.token,
  'request_secret' => request_token.secret}

... and this during callback_phase:

request_token = ::OAuth::RequestToken.new(consumer,
  session['oauth'][name.to_s].delete('request_token'),
  session['oauth'][name.to_s].delete('request_secret'))

It's easy enough to work around this during callback by adding:

session[:oauth] = nil

but shouldn't this be removed by omniauth-twitter?

Intermittent “invalid_credentials” failure for some users

I've implemented OmniAuth + Twitter strategy. It works most of the time for most users. But some users have been getting a consistent failure, and I have not been able to reproduce it or track it down. After logging in to twitter, the user is redirected to

/auth/failure?message=invalid_credentials

I was able to run an HTTP debugger on one users machine during a failure to see the web traffic, and saw the following:

302 GET       myserver.com/auth/twitter
    CONNECT   api.twitter.com:443
401 GET       myserver.com/auth/twitter/callback?oauth_token=....&oauth_verifier=....
302 GET       myserver.com/auth/twitter/callback?oauth_token=....&oauth_verifier=....
401 GET       myserver.com/auth/failure?message=invalid_credentials&strategy=twitter
302 GET       myserver.com/auth/failure?message=invalid_credentials&strategy=twitter

Once this starts happening for a user, it happens consistently over and over, and even clearing cookies and restarting the browser doesn't fix it. Not sure - but it may be only happening to a user that has logged in the day before and kept their browser open.

I implemented the twitter login in a very lightweight method as you'll see:

user.rb:

class User

  attr_accessor :name, :screen_name, :twitter_secret, :twitter_token

  def initialize(auth)
    @screen_name = auth['info']['nickname']
    @twitter_secret = auth["credentials"]["secret"]
    @twitter_token = auth["credentials"]["token"]
    @name = auth["info"]["name"]
  end

end

session_controller.rb:

class SessionsController < ApplicationController

  def reset_and_auth
    reset_session
    redirect_to '/auth/twitter?force_login=true'
  end

  def create
    user = User.new(request.env["omniauth.auth"])
    session[:current_user] = user
    redirect_to root_path, :notice => "Signed in!"
  end

  def destroy
    session.delete(:current_user)
    redirect_to root_path, :notice => "Signed out!"
  end

  def failure
    flash[:auth_failure] = params[:message]
    redirect_to root_path
  end

end

relevant parts of application_controller.rb:

helper_method :current_user

and

def current_user
  session[:current_user]
end

initializers/omniauth.rb:

twitter_config = YAML.load_file(File.join(Rails.root,'config','twitter.yml'))[Rails.env]

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, twitter_config['consumer_key'], twitter_config['consumer_secret']
end

Other notes of interest (after much googling)

  • This is running on Heroku, so I don't think server Time sync could be the issue
  • The app on dev.twitter.com is configured with a matching callback URL, and a matching hostname
  • The keys and tokens are obviously correct, because it works for most users, most of the time
  • This can't be a problem of actual wrong credentials, because in that case the user gets a message about the password being wrong on the twitter login page and doesn't get redirected
  • Once this happens to one user, it happens consistently and they can't login on that browser. However they can login on a different browser. Also about a day or so later they can login again
  • From browsing the source of the oauth gem, I think it is raising an ::OAuth::Unauthorized exception here https://github.com/intridea/omniauth-oauth/blob/master/lib/omniauth/strategies/oauth.rb

Gem versions:

oauth (0.4.6)
omniauth (1.1.0)
  hashie (~> 1.2)
  rack
omniauth-oauth (1.0.1)
  oauth
  omniauth (~> 1.0)
omniauth-twitter (0.0.12)
  multi_json (~> 1.3)
  omniauth-oauth (~> 1.0)
rails (3.2.6)

Trouble switching between read and read+write logins

Thanks for making this!

My app has some users who need read+write, but the majority just need read, so my login link is: "auth/twitter?x_auth_access_type=read"

For users who need read+write, I use: "auth/twitter?x_auth_access_type=write"

Both work, but if a user who originally logged in with one type of permission tries to login using the other one, twitter hangs with the message "(twitter) Request phase initiated."

Using this link: "auth/twitter?use_authorize=true" makes it work so either type of user can login, but it requires users to re-authorize the app each time they login (as it's supposed to).

Is there a way that users can switch between the two x_auth options without it hanging, or do I just need to require all users to re-authorize the app each time using use_authorize=true for it to work? My goal is for the majority of users to have seamless read only login from homepage, but then to not have it break if a previous read+write user tries that main login on the homepage (they would then click the read+write link from within the app when they need to authorize writes).

No redirect after login

Rails 3.2.11
omniauth-facebook works but omniauth-twitter not with the same setup.
Setup is minimal like in https://github.com/railscasts/241-simple-omniauth cast.
After https://api.twitter.com/oauth/authenticate?oauth_token=u6kWqVH3qY8bg7hMP5dFcHcPGSjKWnZ3YACNP6FsK0 twitter redirect me to https://api.twitter.com/oauth/authenticate. And nothing happens.
I develop with Pow so specify http://rangers.dev/auth/twitter/callback in Settings tab.
Thanks for any help you can provide.

Can x_auth_access_type parameter be used in initializer?

I've tried to find a way to get the x_auth_access_type paremeter passed to Twitter's request_token API method, but I can't seem to find any way. Is there a way? My application is registered for read+write access, but I want to allow normal users to authorize just read access, so I want to pass x_auth_access_type="read".

I managed to get the parameter added to the authorize URL, but that doesn't work.

It would be nice if it were like the google_oauth2 strategy, able to add the parameter within the initializer.

Unable to request a token when using multiple applications

I've configured devise + omniauth as documented on omniauth wiki: https://github.com/intridea/omniauth/wiki/Setup-Phase

My initializer (FB is the same):

provider :twitter, nil, nil, setup: true

routes.rb:

get '/settings/auth/:provider/setup' => 'settings/authorization_callbacks#setup'

This is the setup action

def setup
  application_id = params[:application_id].present? ? params[:application_id] : request.env["rack.session"]["omniauth.params"]["application_id"]
  application = Application.find(application_id)
  request.env['omniauth.strategy'].options[:client_id] = application.identifier
  request.env['omniauth.strategy'].options[:client_secret] = application.secret
  render :text => "Setup complete.", :status => 404
end

Result is 400 Bad Request and I have no idea why...
I checked and the right application is called, setting the right values in the "omniauth.strategy".

This is the exception raised: https://gist.github.com/ngw/1621d624a3d4ad4d683c

Callback url has been configured and is correct.

Maybe someone who already implemented this can guess what's the problem with my code or help me debug this? Thanks in advance.

dynamic callback url

Hey Arun,

Twitter supports dynamic oauth_callback URLs per OAuth 1.0a. It would be great if you could configure in omniauth-twitter gem for this feature.

Cheers,
Arjun Urs

Omniauth::NoSessionError: Session Expired

I'm getting session expired for twitter recently after updating the gem

(twitter) Callback phase initiated.
(twitter) Authentication failure! session_expired: OmniAuth::NoSessionError, Session Expired
OmniAuth::NoSessionError - Session Expired:
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-oauth-1.0.1/lib/omniauth/strategies/oauth.rb:46:in callback_phase' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:219:incallback_call'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:175:in call!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:157:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:177:in call!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:157:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/omniauth-1.1.1/lib/omniauth/builder.rb:48:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:816:inforward'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:885:in route_missing' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:846:inroute!'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:842:in route!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:842:inroute!'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:842:in route!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:indispatch!'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in block in call!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:inblock in invoke'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in catch' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:ininvoke'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in call!' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/nulllogger.rb:9:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:incontext'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in context' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in block in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:insynchronize'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:134:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/urlmap.rb:64:in block in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/urlmap.rb:49:ineach'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/lint.rb:48:in_call'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/lint.rb:36:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/chunked.rb:43:in call' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:incall'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:535:in process_client' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:610:inworker_loop'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:491:in spawn_missing_workers' /Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:141:instart'
/Users/ftaher/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/unicorn-4.4.0/bin/unicorn:121:in <top (required)>' /Users/ftaher/.rbenv/versions/1.9.3-p194/bin/unicorn:23:inload'
/Users/ftaher/.rbenv/versions/1.9.3-p194/bin/unicorn:23:in `

'

I have tried almost everything but it's not working for twitter.

Any help or direction to solution is much appreciated.

Thanks

Update omniauth_oauth to omniauth_oauth2

Hello Guys!

I'am developing one application which use many providers to sign in, like facebook, gmail, twitter, github...

I noticed that only omniauth-twitter doesn't use omniauht-oauth2 , is there any special reason for that?

Is there anyway, I can contribute to update omniauth-oauth to omniauth-oauth2, if it is possible.

Best regards.

"Could not authenticate you" error message

Hi,
I setup a new Twitter application, configured the token and secret into my devise config, went to sign in via Twitter, properly got redirected to their site, logged in, and was properly redirected to my omniauths success controller callback. However, the response appears to have failure messages in it and I can't figure out where it's going wrong.

As you'll see in the response below, it is claiming to have failed authentication, and yet, the user id is in the response, and using a bit of hackery, I can get to the screen_name via:
auth = request.env["omniauth.auth"]
screen_name = auth.extra.access_token.instance_variable_get(:@params)[:screen_name]

However, I cannot get to the screen name by doing:
auth.info.nickname (as most of the documentation implies I can do)

Here is what my response looks like, pretty-printed:

{"provider"=>"twitter",
"uid"=>"1549153850",
"info"=>
{"nickname"=>nil,
"name"=>nil,
"location"=>nil,
"image"=>nil,
"description"=>nil,
"urls"=>{"Website"=>nil, "Twitter"=>"https://twitter.com/"}},
"credentials"=>
{"token"=>"MY_TOKEN,
"secret"=>"MY_SECRET"},
"extra"=>
{"access_token"=>
#<OAuth::AccessToken:0x007fe40d3aee88
@consumer=
#<OAuth::Consumer:0x007fe409a453e0
@http=#<Net::HTTP api.twitter.com:443 open=false>,
@http_method=:post,
@key="M0LBDry25iHs3ib6wdFW8w",
@options=
{:signature_method=>"HMAC-SHA1",
:request_token_path=>"/oauth/request_token",
:authorize_path=>"/oauth/authenticate",
:access_token_path=>"/oauth/access_token",
:proxy=>nil,
:scheme=>:header,
:http_method=>:post,
:oauth_version=>"1.0",
:site=>"https://api.twitter.com"},
@secret="MY_SECRET",
@uri=#<URI::HTTPS:0x007fe40d3a9960 URL:https://api.twitter.com>>,
@params=
{:oauth_token=>"MY_TOKEN",
"oauth_token"=>"MY_TOKEN",
:oauth_token_secret=>"MY_SECRET",
"oauth_token_secret"=>"MY_SECRET",
:user_id=>"1549153850",
"user_id"=>"1549153850",
:screen_name=>"TestTes99570751",
"screen_name"=>"TestTes99570751"},
@response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>,
@secret="MY_SECRET",
@token="MY_TOKEN">,
"raw_info"=>
{"errors"=>[{"message"=>"Could not authenticate you", "code"=>32}]}}}

My gem versions are:
omniauth-twitter-1.0.0.gem
omniauth-1.1.4
devise-2.2.4

"@sessions" does not exist

Apparently this issue only happens on the iPhone and iPad.

Here's how to replicate the issue. I tweeted on Twitter. The tweet contains a link that points to by web app: https://www.foobar.com/1 (ps This is a dummy link. You can use your own link).

On the iPhone or Ipad, open up the Twitter App. Search for the tweet. Tap on the link (https://www.foobar.com/1).

The page should redirect you back to "/auth/twitter?use_authorize=true". Everything works fine so far. The user is sent to Twitter's login portal/form. However, after the user fills out the form and submits it. Instead, of being redirected back to our web app, he is sent to Twitter where it says:

"@sessions" does not exist

Anyone else experience this before?

The issue also seems apparent with other people:
https://twitter.com/Starbucks/status/482656278410723328
https://twitter.com/CocaCola/status/483420891393826816
https://twitter.com/RayaVlogs/status/492528237629943808
https://twitter.com/MattNavarraUK/status/494915033634447360
https://twitter.com/WillHillBet/status/497021431021330433

Small typo?

lib/omniauth/strategies/twitter.rb:52

options[:request_params] || {}

Should that be:

options[:request_params] ||= {}

Otherwise that line is slightly useless as there is no assignment that is used and no return.

It's now possible to get user's email address from Twitter, can we do this w/omniauth-twitter?

Buried at the bottom of this Twitter Developer's forum post a Twitter employee finally reveals that you can request access to get the user's email address from this Twitter API Policy Support form.

It is suggested to click the "I need access to special authentication privileges (e.g. xAuth)" radio button, and explain you want access to the user's email address. A common theme seems to be that Twitter support person misunderstands/denies/redirects you somewhere else (it happened to me too). But if you ask again, they will grant you access:

We've enabled requesting email permissions for your app. Please note that this permission is only enabled on new sign-ins to your app. In order to begin, please log into apps.twitter.com and

  • Add a terms of service and privacy policy to your app info
  • Change your token's scope to request email

I also found a checkbox to select in my Twitter app's settings to enable the email permission.

I'm just stuck on how I might do this properly w/omniauth-twitter. I also use devise and it's omniauthable module. I see an array of permissions being used here, just not sure what to include and what else to do.

I apologize for dumping all of this here, but I haven't seen anyone discussing how to solve this now that it's possible.

I am happy to try and submit a PR, any pointers would be appreciated I'm just digging into the code now.

OAuth::Unauthorized 413 Request Entity Too Large

Hi,
my app suddenly fail to connect with twitter. i have also used omniauth_facebook gem which is working fine. couple of days ago it was working fine. i did issued bundle update command after getting this error so both gem were updated. but no luck.

my configuration is :

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, TWITTER_CONSUMER_KEY, TWITTER_SECRET_KEY
  provider :facebook, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, {:scope => FACEBOOK_APP_PERMISSIONS }

end

http://127.0.0.1:3000/auth/twitter page is giving this error. above configuration should have worked for this page if not for other part.

I did double confirmed like twitter redirection url, secret keys. Even i created new app in twitter and tried. i am getting same error again and again here is some line of stack trace.

oauth (0.4.6) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.6) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/omniauth-twitter-6ad2f2eab3a9/lib/omniauth/strategies/twitter.rb:55:in `request_phase'
omniauth (1.1.0) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.0) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.0) lib/omniauth/builder.rb:48:in `call'

Any suggestions??

Don't catch all errors thrown

I am not sure if this is specific to omniauth-twitter or to omniauth in general, but I mistyped something when I was getting information out of the omniauth hash in the callback url. This raised a nil error that was caught by either omniauth or omniauth-twitter. It then sent me to the failure callback with an invalid_response message. That message isn't too helpful. I tried it with other strategies, and they didn't catch the error and redirect to the failure callback. That is why I am posting here.

To repeat the error, in the success callback just try this:

omniauth = request.env['omniauth.auth']
omniauth['garbage']['nothing']

Instead of getting a nil error reported, it will just redirect to the failure callback with a message invalid_response. This message makes it seem like something isn't working with the gem, and in reality we created an exception in our processesing after a successful callback.

401: Failed to validate oauth signature and token.

Setting up a new Rails app with omniauth with a variety of providers. omniauth-github and omniauth-facebook work fine, but I get 401 Unauthorized for omniauth-twitter

I've regenerated my app keys, but no dice, and unfortunately the twitter oAuth tool is down so that they can advertise for a conference.

httplog gives the following log output -- and yes, these are not my real consumer key, nonce, and signature. :)

[httplog] Connecting: api.twitter.com:443
[httplog] Sending: POST http://api.twitter.com:443/oauth/request_token
[httplog] Header: accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[httplog] Header: accept: */*
[httplog] Header: user-agent: OAuth gem v0.4.7
[httplog] Header: content-length: 0
[httplog] Header: content-type: application/x-www-form-urlencoded
[httplog] Header: authorization: OAuth oauth_callback="https%3A%2F%2Fdevhost.local%2Fauth%2Ftwitter%2Fcallback", oauth_consumer_key="5fcXQMF6qqbghtxOp9xRkogUV", oauth_nonce="mkOSKXt1wnpWA0f0BiWagHwVB6VPoiJwXq1u9clC", oauth_signature="4nBea1wP55anP%2Fnd88AcGUH3xl5%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1410135434", oauth_version="1.0"
[httplog] Header: connection: close
[httplog] Data: 
[httplog] Status: 401

Any ideas? Anything obvious I might have missed?

Gzip response from twitter API

It is for ruby 2.0.

I had the exception at the beggining of authentication:

NoMethodError (undefined method `encoding' for nil:NilClass):
  /home/storage_production/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/cgi/util.rb:7:in `escape'
  oauth (0.4.7) lib/oauth/tokens/request_token.rb:29:in `block in build_authorize_url'
  oauth (0.4.7) lib/oauth/tokens/request_token.rb:29:in `each'
  oauth (0.4.7) lib/oauth/tokens/request_token.rb:29:in `map'
  oauth (0.4.7) lib/oauth/tokens/request_token.rb:29:in `build_authorize_url'
  oauth (0.4.7) lib/oauth/tokens/request_token.rb:9:in `authorize_url'
  omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:37:in `request_phase'
  omniauth-twitter (1.0.1) lib/omniauth/strategies/twitter.rb:60:in `request_phase'

The investigation revealed that issue with gziped response from twitter api and ruby 2.0 doesn't handle it by default.
This stackoverflow answer solves the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.