Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Q&A How do you add "Sign In with Google" to a Ruby on Rails web application that is using the Devise authentication framework?

Step 1: Locate your Gem file and add the omniauth-google-oauth2 gem to it. Step 2: Add configuration for Google OAuth2 to your Devise configuration file, located in /config/initializers/devise.rb....

posted 10mo ago by Julius H.‭

Answer
#1: Initial revision by user avatar Julius H.‭ · 2024-02-12T16:43:16Z (10 months ago)
Step 1: Locate your Gem file and add the omniauth-google-oauth2 gem to it.

Step 2: Add configuration for Google OAuth2 to your Devise configuration file, located in /config/initializers/devise.rb.

Step 3: Create authentication credentials (a Client ID and Client Secret) on the Google Cloud console, for an OAuth2 application. Enter them into the Google OAuth2 configuration in the Devise configuration file.

Step 3: Create a controller that handles the backend logic. When the user "signs in with Google", their browser opens a new page in which they authenticate with Google. When successful, Google sends an authentication token back to the page which the user came from. This works because of a '*callback URL*'. A callback URL is a URL that the original, calling app provides to Google, when it redirects the user to Google. Once authenticated, Google knows where to "call back", and return the authentication information *back* to. What it specifically returns is an *activation code*. This is a session token which permits accessing particular data from Google. Your callback controller has methods to determine what data you want to pull in from Google, once authenticated, such as the user's name, email, profile picture, etc. The callback controller decides how to store that information in the user authentication database on your own application's side. It also determines how to handle the authentication logic regarding if there is a new user being created or a pre-existing user being signed in; as well as if Google Sign-In can be used to connect to alternative sign-in methods, such as signing in to the same profile with GitHub, or with a user-created profile using an email, username, and/or password.

Step 4: Update the model. Update the application to enable the user to click the Sign in with Google button.