Below is the relevant code (do let me know if I'm missing anything!).
routes.rb:
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
devise_scope :user do
match '/sessions/user', to: 'devise/sessions#create', via: :post
get '/join' => 'users/registrations#new'
end
resources :users do
resources :video_lessons do
resources :likes
end
end
resources :users, only: [:show, :index]
devise.rb:
if Rails.env.production?
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID_PROD'[, ENV['GOOGLE_CLIENT_SECRET_PROD'], {}
else
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID_DEV'], ENV['GOOGLE_CLIENT_SECRET_DEV'], {}
end
omniauth_callbacks_controller.rb
def google_oauth2
# 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?
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) # Removing extra as it can overflow some session stores
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
end
end
devise/registrations/new.html.erb
<%= link_to "Sign up with Google", user_google_oauth2_omniauth_authorize_path %>
The authorized redirect URIs in my Developer's Console are: http://localhost:3000/users/auth/google_oauth2 and https://localhost:3000/users/auth/google_oauth2
I've followed the docs (https://github.com/zquestz/omniauth-google-oauth2) exactly, to no avail.
Thank you for your help!