What I was addicted to when implementing google authentication with rails

This time, I summarized what I was addicted to when implementing google authentication with rails, so for reference. Articles I referred to when implementing Google authentication ↓ [Rails] Implement user registration on Facebook / Twitter / Google at explosive speed using Devise & Omniauth

Error 400: invalid_request Missing required parameter: client_id

First one. I got an error when I tried to authenticate by selecting an account on the Google authentication page. I was told that there is no client_id. There are two causes ① There was a space ② The key was entered as it was without using .env

① Space


config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'] ,ENV['GOOGLE_CLIENT_SECRET'], skip_jwt: true



config.omniauth :google_oauth2,ENV['GOOGLE_CLIENT_ID'],ENV['GOOGLE_CLIENT_SECRET'],skip_jwt: true

Changed to. It looks like I didn't need space. There was space on the reference site.

② The key was entered as it was without using .env As far as I can see from other sites, it seems that some people could go as it is, but it was not possible in my environment. If you can't solve it, try adding gem'dotenv-rails'.

Email authentication is not done

The next thing that came out was this error If you do it normally, it will be displayed if the email is not authenticated. this is


class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  # callback for google
  def google_oauth2

  # common callback method
  def callback_for(provider)
    @user = User.from_omniauth(request.env["omniauth.auth"])
    @user.skip_confirmation!← with this
    @user.save!← This!
    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
      session["devise.#{provider}_data"] = request.env["omniauth.auth"].except("extra")
      redirect_to new_user_registration_url

  def failure
    redirect_to root_path

@user.skip_confirmation! @user.save! I solved it by putting it in the controller.

Petit promotion

I made an app called Public Diary. It's an app that allows you to publish your diary (it's possible not to publish it), but I'm the only one using it (crying). Please check it because it is updated almost every day. Please.

URL: https://public-diary.herokuapp.com/


Actually, I have tried to implement sns authentication about 4 times and failed repeatedly. I was able to do it for the first time this time, but I was very happy when I was able to do it. Thank you for watching so far.

Recommended Posts

What I was addicted to when implementing google authentication with rails
What I was addicted to when introducing the JNI library
What I was addicted to while using rspec on rails
I was addicted to setting default_url_options with Rails devise introduction
What I was addicted to with the Redmine REST API
What I was addicted to when developing a Spring Boot application with VS Code
I was addicted to doing onActivityResult () with DialogFragment
Memorandum: What I was addicted to when I hit the accounting freee API
[Rails] I was addicted to the nginx settings when using Action Cable.
Problems I was addicted to when building the digdag environment with docker
A memo that I was addicted to when making batch processing with Spring Boot
The story I was addicted to when setting up STS
I was addicted to starting sbt
I was addicted to WSl when trying to build an android application development environment with Vue.js
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
[Rails] I want to add data to Params when transitioning with link_to
I was addicted to the roll method
I was addicted to the Spring-Batch test
[Rails] How to solve ActiveSupport :: MessageVerifier :: InvalidSignature that I was addicted to when introducing twitter login [ActiveStorage]
A story I was addicted to when testing the API using MockMVC
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was addicted to unit testing with the buffer operator in RxJava
I tried to make Basic authentication with Java
I want to play with Firestore from Rails
What I did when I converted java to Kotlin
[Rails] I want to load CSS with webpacker
SpringSecurity I was addicted to trying to log in with a hashed password (solved)
I was addicted to the NoSuchMethodError in Cloud Endpoints
I tried what I wanted to try with Stream softly.
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
I was addicted to the record of the associated model
I want to authenticate users to Rails with Devise + OmniAuth
When importing CSV with Rails, it was really easy to use the nkf command
Addicted to the webpacker that comes standard with Rails 6
A story I was addicted to when getting a key that was automatically tried on MyBatis
When I tried to scroll automatically with JScrollBar, the event handler was drawn only once.
When I tried to run Azure Kinect DK with Docker, it was blocked by EULA
[Rails] What to do when the view collapses when a message is displayed with the errors method
A story I was addicted to with implicit type conversion of ActiveRecord during unit testing
How to automatically generate ER diagram when migrating with Rails6
How to set environment variables when using Payjp with Rails
[Rails] I tried to create a mini app with FullCalendar
I entered from Rails and didn't know what [attr_accessor] was
I was addicted to looping the Update statement on MyBatis
What to check when rails db: migration does not pass
How to specify db when creating an app with rails
I was addicted to the setting of laradock + VSCode + xdebug
[Rails] I tried to implement batch processing with Rake task
What happens to instance variables when copying an instance with ruby
I was addicted to using Java's Stream API in Scala
I knew what reflection was
SNS authentication using Rails google
Technical causes and countermeasures for the points I was addicted to with the first Android app & Kotlin
I was angry with proc_open (): fork failed when trying to composer update inside a Docker container
What to do if the app is not created with the latest Rails version installed when rails new
[Words spelled to me when I was in the first grade ⑦] What I want you to include at least with the Visual Studio Code extension
[Circle CI] A story I was addicted to at Start Building
I tried to summarize what was asked at the site-java edition-
I get a 404 error when testing forms authentication with Spring Security
When I push to Heroku, I get angry with Precompiling assets failed.