我有2种登录方式进入我的应用程序。第一种方式是通过电子邮件登录,下一个是通过社交媒体登录。
我已经安装了devise和omniauth,omniauth-facebook,twitter和google plus。我已经成功实现了通过设备的正常登录,但当我尝试通过访问/ auth / facebook通过fb或twitter或gplus登录时,它表示找不到路由。
Rails.application.routes.draw do
devise_for :users
root to: 'visitors#index'
get '/auth/:provider/callback' => 'sessions#create'
get '/signin' => 'sessions#new', as: :signin
get '/signout' => 'sessions#destroy', as: :signout
get '/auth/failure' => 'sessions#failure'
end
// session_controller.rb
class SessionsController < ApplicationController
def new
redirect_to '/auth/facebook'
end
def create
auth = request.env['omniauth.auth']
user = User.where(provider: auth['provider'],
uid: auth['uid'].to_s).first || User.create_with_omniauth(auth)
reset_session
session[:user_id] = user.id
redirect_to root_url, notice: 'Signed in!'
end
def destroy
reset_session
redirect_to root_url, notice: 'Signed out!'
end
def failure
redirect_to root_url, alert: "Authentication error: #{params[:message].humanize}"
end
end
// omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
scope: 'public_profile', info_fields: 'id,name,link'
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_SECRET'],
scope: 'profile', image_aspect_ratio: 'square', image_size: 48,
access_type: 'online', name: 'google'
end
答案 0 :(得分:1)
取消注释
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable //, :omniauthable
user.rb中的做了伎俩