0
twitterメールを使用してdevise :omniauthable
を利用することはできますか?twitterの電子メールを作成する
私はFacebookのメールを取得し、この方法でユーザーを作成することができます。
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token['extra']['user_hash']
if user = User.find_by_email(data["email"])
user
else # Create a user with a stub password.
User.create!(:email => data["email"], :password => Devise.friendly_token[0,20])
end
end
コントローラ:私はuser_id
、uid
を持って入ってくるのparamsでTwitterのOAuthのために、このようなものを使用している場合
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.facebook_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def twitter
@user = User.find_for_twitter_oauth(env['omniauth.auth'])
if @user.persisted?
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', :kind => 'Twitter'
sign_in_and_redirect @user, :event => :authentication
else
flash[:notice] = I18n.t 'devise.omniauth_callbacks.failure', :kind => 'Twitter', :reason => 'User not found'
redirect_to new_user_session_path
end
end
end
、 credentials
、secret
などですが、メールはありません。この方法で入手できますか?私はユーザーテーブルの新しいフィールドを追加したり、ユーザーID、oauth prowiders、およびoauth IDを持つ新しいテーブルを追加することは望ましくありません。
Mbもっときれいなやり方warden戦略with twitter?