Twitter Oauth Strategy with Warden + Develop Gems Authenticity for Ruby

Come up with an authentic Ruby stone based on Warden (another self-identifier) ​​that does not support Twitter Oauth as an authentication strategy, BUT Warden. There is a way to use Devise's Warden Twitter Oauth strategy, but I can't figure it out. I use the following block in the dev configuration file:

config.warden do |manager| manager.oauth(:twitter) do |twitter| twitter.consumer_secret = <SECRET> twitter.consumer_key = <KEY> twitter.options :site => 'http://twitter.com' end manager.default_strategies.unshift :twitter_oauth end 

But I keep getting all kinds of error messages. Does anyone know how to make this work? I suppose there is something else here (setting up a new link / route to talk to Warden, maybe adding Devise User model attributes, etc.), but I can't figure out what it is. Please help.

+4
source share
4 answers
 # Needed gems. Add to your Gemfile if you are using Rails3. gem 'devise' gem 'warden_oauth' #models/user.rb devise :token_authenticatable, :oauthable # <-- Must have these #/config/initializers/devise.rb require 'warden_oauth' config.warden do |manager| manager.oauth(:twitter) do |twitter| twitter.consumer_secret = '<SECRET>' twitter.consumer_key = '<CONSUMER KEY>' twitter.options :site => 'http://twitter.com' end manager.default_strategies(:scope => :user).unshift :twitter_oauth end Warden::OAuth.access_token_user_finder(:twitter) do |access_token| User.find_or_create_by(:token => access_token.token, :secret => access_token.secret).tap do |user| #... end end # Link to "Login With Twitter" somewhere in your view <%= link_to( "Login With Twitter", user_session_path(:warden_oauth_provider => 'twitter') ) %> 
+4
source

Omniauth makes this easy. There is Railscast when using Omniauth with Devise ( part 1 , part 2 ).

+3
source

This solution works. You just need to make sure that you invoke the protected action when specified: warden_oauth_provider => 'twitter', otherwise Rails will simply ignore it.

To use the above example, change the link to:

 <%= link_to( "Login With Twitter", user_session_path(:warden_oauth_provider => 'twitter'), :method => :post ) %> 
0
source

Try checking out a class or module called Twitter (you can check this by running script / console, then type Twitter), if you did, call it something nonexistent.

0
source

Source: https://habr.com/ru/post/1310287/


All Articles