omniauth-facebook
とomniauth-google
のoAuthを正常に実装しましたが、メールアドレスを提供しないため、omniauth-twitter
を実装するのが難しいです。Rails Devise Twitter OAuthはOAuth登録を継続するフォームにリダイレクト
私はインターネット上で利用可能なソリューションを検索しましたが、Deviseの電子メールの検証を削除するという1つの解決方法が指摘されましたが、私のアプリケーションには電子メールの検証が必要です。
oAuthの登録を完了するためにユーザーが新しいメールアドレスを入力する必要がある新しいフォームにユーザーをリダイレクトするだけですが、oAuthデータとリンクして登録を完了する方法がわかりませんユーザー名とパスワードは電子メールだけがそのフォームに表示されている間、空想にすることはできませんので、私はフォームを送信するときにエラーを取得しているので。
CallbackController
def twitter
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_data"] = request.env["omniauth.auth"].except("extra")
redirect_to twitter_register_path
end
end
twitter_register_path
は、ユーザーが登録を完了するために彼の電子メールアドレスを記入しなければならないのビューが含まれています。
ユーザーモデル
def self.from_twitter_omniauth(auth,email)
where(provider: auth["provider"], uid: auth["uid"]).first_or_create do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.email = email
user.name = auth["info"]["name"]
user.password = Devise.friendly_token[0,20]
user.remote_poster_image_url = auth["info"]["image"].gsub('http://','https://')
end
end
Twitterの登録フォーム(twitter_register_path)
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true,label: false %>
</div>
<div class="signup">
<%= f.button :submit, "Sign up",:class =>"register-button" %>
</div>
<% end %>
TwitterのAPIは、最近のアプリケーションは、自分の電子メールのために追加の権限を要求することを可能にするにもかかわらず、私はわかりませんよその実装方法の