我正在尝试在设计之上安装 OmniAuth-Twitter 。我正在关注本教程https://www.youtube.com/watch?v=X6tKAUOMzCs&t=42s,但我收到的错误是我无法在网上找到的。实际上这不是一个错误,在我从Twitter授权应用程序后,它重定向到我的sign_in表单!
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "ididputmykeyhere", "ididputmykeyhere"
end
的routes.rb
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
resources :posts
resources :categories
root 'posts#index'
end
omniauth_callbakcs_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
# Show me what I get from Twitter
raise request.env["omniauth.auth"].to_yaml
@user = User.from_omniauth(request.env["omniauth.auth"])
sign_in_and_redirect @user
end
end
devise.rb
config.omniauth :twitter, ENV["ididputmykeyhere"], ENV["ididputmykeyhere"]
user.rb
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:twitter]
has_many :posts
end
我将 user_twitter_omniauth_authorize_path 链接放置到我的视图中。
它就像跳过我的omniauth_callbacks_controller一样,我将保存到数据库代码,我错过了什么?谢谢你!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +
我刚刚向我的omniauth_callbakcs_controller.rb添加了def失败,我发现该应用就是为了它。
def failure
raise request.env["omniauth.auth"].to_yaml
flash[:error] = 'There was a problem signing you in. Please register or try signing in later.'
redirect_to root_path
end
答案 0 :(得分:0)
太奇怪了,但删除 omniauth.rb 文件解决了这个问题。我在omniauth.rb和devise.rb 文件中定义了 API密钥。也许在多个文件中定义会导致某种冲突。