I am following this paper step by step :https://richonrails.com/articles/google-authentication-in-ruby-on-rails/ And I created a completely new rails app in order to test. But I keep getting the same error: Error: invalid_request
Invalid parameter value for redirect_uri: Raw IP addresses not allowed: http://0.0.0.0:3000/auth/google_oauth2/callback OmniAuth.config.logger = Rails.logger
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, 'CLIENT-ID', 'SECRET', {client_options: {ssl:
{ca_file: Rails.root.join("cacert.pem").to_s}}}
end
routes.rb
Rails.application.routes.draw do
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
get 'signout', to: 'sessions#destroy', as: 'signout'
resources :sessions, only: [:create, :destroy]
resource :home, only: [:show]
root to: "home#show"
end
user.rb
class User < ApplicationRecord
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do
|user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
ApplicationController.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end
SessionController.rb class SessionsController < ApplicationController def create user = User.from_omniauth(env["omniauth.auth"]) session[:user_id] = user.id redirect_to root_path end
def destroy
session[:user_id] = nil
redirect_to root_path
end
end
Please help me! Thanks a lot!
http://localhost:3000/auth/google_oauth2/callback
? – NM Pennypacker