I need to access the Google API, I'm trying to get users to log in to their google account using Devise 2.1.1 and Omniauth (using gem google_oauth2 , since OAuth2 is recommended from Google docs).
Unfortunately, I can't get it to work, it's routes.rb
TestApp::Application.routes.draw do root :to => 'Landing#index' devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } devise_scope :user do get 'sign_in', :to => 'users/sessions#new', :as => :new_session get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_session end end
Then I configured config/initializers/devise.rb to include a line with
config.omniauth :google_oauth2, 'ID', 'SECRET', {access_type: 'offline', approval_prompt: 'force', scope: 'https://www.googleapis.com/auth/analytics.readonly'}
And actually I have a void callback class app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController end
When I click "Sign in to Google," I redirect to Google asking for permission, then return to the callback, and I redirect to the URL http://localhost:3000/sign_in.user with an error
uninitialized constant Users::SessionsController
What is wrong here? I spent 2 days trying to figure it out myself, I played with a lot of configurations, but never worked, it disappointed me.
This is the result of rake routes
root / Landing