I followed the tutorial in the omniauth-google-oauth2 gem file , and when I click on the link to my root (@ pages#home) <%= link_to "Sign up with Google", user_google_oauth2_omniauth_authorize_path %>, I get the error:
Not found. Authentication passthru.
I have confirmed that ENV vars have. I looked at similar topics with no luck. Any idea what I'm doing wrong?
In routes:
Rails.application.routes.draw do
devise_for :users, controllers: { :omniauth_callbacks => "users/omniauth_callbacks" }
My omniauth_callbacks_controller is in /controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"].except(:extra)
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
end
end
end
In my devise.rbfile:
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], {
name: 'my-project',
scope: 'email',
prompt: 'select_account',
image_aspect_ratio: 'original',
image_size: 100,
ssl_verify: false
}
And in my User.rb:
devise :rememberable, :validatable, :omniauthable, :omniauth_providers => [:google_oauth2]
def self.from_omniauth(access_token)
data = access_token.info
user = User.where(:email => data["email"]).first
user
end