Rails google-oauth2 404 - "Not found. Authentication passthru."

When attempting to sign in with Google Oauth, I encounter a 404 error "Not found. Authentication passthru." This worked just a month ago on my site, and I have not changed anything that should have impacted authentication. I've seen several other posts about this, but none have seemed to work in my case.

initializers/devise.rb

Devise.setup do |config|
  config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH_CLIENT_ID'], ENV['GOOGLE_OAUTH_CLIENT_SECRET']
.
.
.

gemfile

gem 'devise', github: 'heartcombo/devise'
gem 'omniauth', '~> 1.6', '>= 1.6.1'
gem 'omniauth-google-oauth2'
gem "omniauth-rails_csrf_protection"

routes.rb

  devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
  devise_scope :user do
    get 'users/sign_in', to: 'users/sessions#new'
    get 'users/sign_out', to: 'users/sessions#destroy'
  end

view

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
    <% if provider = "google_oauth2" %>
      <%= link_to "Sign in with Google", omniauth_authorize_path(resource_name, provider), method: :post, class: "oauth-link" %><br />
    <% else %>
.
.
.

Solution 1:

I was hitting this myself and thought the 404 was some kind of error. I believe it's the intended response when the Omniauth controller doesn't recognize the provider. Try:

<%= link_to "Sign in with Google", user_google_omniauth_authorize_path, method: :post, class: "oauth-link" %>

If you're using Turbo, you'll want to change it to a button_to and set data-turbo: false.