LoginSignup
4
0

More than 1 year has passed since last update.

SNS認証におけるNot found. Authentication passthru.エラーについて

Posted at

概要

 SNS認証(Omniauth使用)時に(今回はGoogle認証を使用した場合となります)おいて、Google認証ページに遷移しようとすると、「Not found. Authentication passthru.」のエラーが出た場合の対処法について記載します。
 SMS認証の導入自体は、下記の記事にお世話になりました。ありがとうございます。

deviseとOmniAuthをRailsアプリケーションに導入しテストする

対処法

 該当部分は、app/views/devise/shared/_links.html.erbにある、認証画面への遷移用リンクとなります。(user_google_oauth2_omniauth_authorize_pathでエラーが生じます)

app/views/devise/shared/_links.html.erb(該当部分のみ抜粋)
<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
  #今回問題となったリンク(自動生成→自身で少し訂正)
    <%= link_to 'Signin with Google', user_google_oauth2_omniauth_authorize_path, method: :post %><br />
  <% end %>
<% end %>

 まず、以下の記事の内容をお試し下さい。

SNS認証ログインでNot found. Authentication passthru.が表示されたときの対処方法
Rails5でrails で google認証ができない「Not found. Authentication passthru.」

 こちらの記事の内容で治れば、それでよかったのですが、私の場合はこれを試してもエラーがなくなりませんでした。
 結論から申し上げると、config/initializers直下に、「omniauth.rb」を作成していただき、以下の内容を記載するとエラーを突破することができました。

omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  OmniAuth.config.allowed_request_methods = [:post, :get]
end

 こちらに関しては、現在私が利用させてもらっているスクールのメンター様に教えていただいた方法になります。
 正直完全には理解できておりませんが、OmniAuthでの認証時にPOSTメソッドを許可する記述だそうです。これがない状態だと、うまくPOSTメソッドが機能しない状態だったそうです。

 これで私の場合は認証機能がうまく動きました。どなたかの参考となれば幸いです。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0