###前提・実現したいこと
webサイトに、devise,omniauthを使用して
ソーシャルログインを実装したいのですが、"Not found. Authentication passthru."とでてしまいます。
deviseのgitを見ながらしたのですが、初心者なので解決法がわからず質問に至りました。
お知恵を貸していただけると幸いです。
###該当のソースコード
/models/userrb class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :confirmable, :validatable, :omniauthable, omniauth_providers: [:line, :facebook] def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = auth.info.email user.password = Devise.friendly_token[0,20] user.name = auth.info.name # assuming the user model has a name user.image = auth.info.image # assuming the user model has an image # If you are using confirmable and the provider(s) you use validate emails, # uncomment the line below to skip the confirmation emails. # user.skip_confirmation! end end
/routes.rb Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users, controllers: { omniauth_callbacks: "omniauth_callbacks" } get '/', to: 'top#index' get '/login', to: 'top#login' get '/products', to: 'top#productspage' end
/omniauth_callbacks_controller_rb class OmniauthCallbacksController < Devise::OmniauthCallbacksController def line; basic_action end private def basic_action @omniauth = request.env['omniauth.auth'] if @omniauth.present? @profile = SocialProfile.where(provider: @omniauth['provider'], uid: @omniauth['uid']).first if @profile @profile.set_values(@omniauth) sign_in(:user, @profile.user) else @profile = SocialProfile.new(provider: @omniauth['provider'], uid: @omniauth['uid']) email = "example@gmail.com" @profile.user = current_user || User.create!(email: email, password: Devise.friendly_token[0, 20]) @profile.set_values(@omniauth) sign_in(:user, @profile.user) redirect_to edit_user_path(@profile.user.id) and return end end redirect_to new_user_session_path end def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end def failure redirect_to root_path end end
/devise.rb Devise.setup do |config| config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' require 'devise/orm/active_record' config.omniauth :facebook, "XXXX", "XXXX", scope: 'email', info_fields: 'email,name' config.case_insensitive_keys = [:email] config.strip_whitespace_keys = [:email] config.skip_session_storage = [:http_auth] ,,,
###試したこと
・githubやqiitaなどに上がっているdevise+omniauth認証を参照して、
routes.rbやcontrollerのアプローチを変更したり色々しましたが、わかりませんでした。
切実です。どうかよろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。