Rails 6 Omniauth Google SignIn

Step 7: Now once it gives you the confirmation message that it was created go ahead and click on CREDENTIALS in the left menu.

<%= link_to "Log In With Google", '/auth/google_oauth2'%>
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV['GOOGLE_CLIENT_KEY'], ENV['GOOGLE_CLIENT_SECRET']
end
get '/auth/:google_oauth2/callback' => 'sessions#google'
def google
@user = User.find_or_create_by(email: auth["info"]["email"]) do |user|
user.name= auth["info"]["first_name"]
user.password= SecureRandom.hex(8)
end
if @user && @user.id
session[:user_id] = @user.id
redirect_to custom_path
else
redirect_to another_path
end
end
private def auth
request.env['omniauth.auth']
end

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Implement DAG Dependencies Using TriggerDagRun Operator

Raw Engineering Interview Experience 2019

CUDA by Example : Notes

Kickstart 2018 Round A — Even Digits

Dissecting Front-end Job Titles

Moving AWS Resources Between CloudFormation Stacks

Cloud Formation events showing Import In Progress and then Import Complete

Some of the Funny commands in Linux

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nerly Ton

Nerly Ton

More from Medium

Let us build a community of folks who build developer tools

A picture of physical tools signifying developer tools

Rails in 2021

Rust The Most Loved Programming Language

We found some Ruby under the Rails