Search code examples
ruby-on-railsdeviseomniauth

Facing trouble to login with google_oauth2 using omni + desive authenication


I am work on project and I need to add social authentication so I choose omniauth + devise for authentication. Firstly I started from Facebook authentication that is working fine after that I have use gem 'omniauth-facebook', '~> 4.0' for google authentication and follow instructions from this article but its show There was a problem signing you in. Please register or try signing in later. from following code which I use in OmniauthController

def google_oauth2
    @user = User.create_from_google_data(request.env['omniauth.auth'])
    if @user.persisted?
        sign_in_and_redirect @user
        set_flash_message(:notice, :success, kind: 'Google') if is_navigational_format?
    else
        flash[:error] = 'There was a problem signing you in through Google. Please register or try signing in later.'
        redirect_to new_user_registration_url
    end 
end

def failure
    flash[:error] = 'There was a problem signing you in. Please register or try signing in later.' 
    redirect_to new_user_registration_url
end

Its call a failure method from OmniauthController. I don't know what's the issue behind this and I`m wondering from yesterday I googled also but not get good stuff to resolve this issue.


Solution

  • I have resolved my issue, actually I have created a new google credential(App Id, Secret key) but forgot to enable API. Now I have enabled google API and google authentication is working fine.

    Enable API