質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

2回答

4286閲覧

Omniauthを使ってLINE,Facebook認証をしようとしたら"Not found. Authentication passthru."と出てしまう

azusasaeki

総合スコア6

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2017/09/26 13:01

###前提・実現したいこと
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のアプローチを変更したり色々しましたが、わかりませんでした。
切実です。どうかよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

過去の設定から若干変わっているようです。
rails routesでルート見た際に末尾にpassthruがあるルートは表示されていますか?
link_to等で設定しているURLを変更してみてください。
(もしかしたらcallbackのURLを使っていたりするかもしれません。私も同じことやってました)

投稿2019/05/19 02:36

params_bird

総合スコア26

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

devise.rbのconfig.omniauthにlineの設定がないですが、上記はlineの認証かfbの認証どちらで出るエラーでしょうか?

投稿2018/04/20 18:01

編集2018/04/22 11:43
GenseiTakeda

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問