Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"an error ocurred" when receiving the callback from google #1090

Closed
mgs96 opened this issue Feb 13, 2018 · 1 comment
Closed

"an error ocurred" when receiving the callback from google #1090

mgs96 opened this issue Feb 13, 2018 · 1 comment

Comments

@mgs96
Copy link

mgs96 commented Feb 13, 2018

Hello, I'm trying to implement omniauth with google, I was able to redirect to google, select account and then redirect to the callback route, but I'm getting an error ocurred error when rendering omniauthsuccess, the users are being created, I can see them in the rails console, I have already looked some tutorials like this one but no success

screenshot_1

the versions of the gems are the following:

  • devise (4.3.0)
  • devise_token_auth (0.1.42)
  • oauth2 (1.4.0)
  • omniauth (1.8.1)
  • oauth2 (1.4.0)
  • omniauth (1.8.1)
  • omniauth-google-oauth2 (0.5.3)
  • omniauth-oauth2 (1.5.0)
  • rails (5.1.4)

The project was created using the --api flag, I have already configured the devise initializer.

Devise.setup do |config|
    config.navigational_formats = [ :json ]
    config.mailer_sender = "[email protected]"
    config.omniauth :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"], {}
end

the routes are the following:

Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth', controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }, defaults: { format: :json }

  get 'login', to: redirect('/auth/google_oauth2'), as: 'login'
  get 'logout', to: 'sessions#destroy', as: 'logout'
  get 'auth/failure', to: redirect('/')

  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  namespace :api do
    namespace :v1 do
      resources :products
    end
  end
end

currently I'm not using any front end, just testing in my browser.

Thanks in advance.. and If I'm able to pull this off, I will gladly contribute with a tutorial, or a README, or something, thanks again

@13LD
Copy link

13LD commented Mar 6, 2018

Try to make like this - it works for me

provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
{
    display: 'popup',
    prompt: 'select_account consent',
    access_type: 'offline',
    scope: 'userinfo.email',
    redirect_uri: 'http://HOST_APP/omniauth/google_oauth2/callback'
}

@mgs96 mgs96 closed this as completed Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants