前提・実現したいこと
OmniAuthを利用したSNSログイン機能の実装時エラーを解決したい。
googleからログインしようとすると下記のようなエラーが出ます。
ちょっと八方塞がりで何から試せば良いのかわからなくなりました。
発生している問題・エラーメッセージ
401. That’s an error. Error: deleted_client The OAuth client was deleted. Request Details That’s all we know.
該当のソースコード
RubyonRails
1class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 2 def facebook 3 callback_from :facebook 4 end 5 6 def google_oauth2 7 callback_from :google 8 end 9 10 private 11 12 def callback_from(provider) 13 provider = provider.to_s 14 @user = User.find_for_oauth(request.env['omniauth.auth']) 15 16 if @user.persisted? 17 flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: provider.capitalize) 18 sign_in_and_redirect @user, event: :authentication 19 else 20 session[:nickname] = @user.nickname 21 session[:email] = @user.email 22 session[:password] = @user.password 23 session[:provider] = @user.provider 24 session[:uid] = @user.uid 25 redirect_to new_user_registration_path 26 end 27 end 28end 29
class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :omniauthable, omniauth_providers: %i[facebook google_oauth2] has_many :questions has_many :comments def self.find_for_oauth(auth) user = User.where(uid: auth.uid, provider: auth.provider).first unless user user = User.create( uid: auth.uid, provider: auth.provider, nickname: auth.info.name, email: auth.info.email, password: Devise.friendly_token[0, 20] ) end end end
class Users::RegistrationsController < Devise::RegistrationsController class Users::RegistrationsController < Devise::RegistrationsController def sns @user = User.new( nickname: session[:nickname], email: session[:email], password: session[:password], password_confirmation: session[:password], ) end def create super @user.uid = session[:uid] @user.provider = session[:provider] @user.save end end end
・config/initializers/devise.rb
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'] config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
・.env
FACEBOOK_KEY = '**************************' FACEBOOK_SECRET = '***********************************' GOOGLE_CLIENT_ID ='*****************************************************com' GOOGLE_CLIENT_SECRET = '*********************'
あなたの回答
tips
プレビュー