###前提・実現したいこと
実現したいこととしては、以下のgemを使ってfacebook認証を実装したいとおもっています。
gem 'devise' gem 'omniauth' gem 'omniauth-facebook' gem 'dotenv-rails'
###発生している問題・エラーメッセージ
deviseを使ってコントローラー、モデル、ビューの生成は終わっています。
モデル名はuser
です。
どこを直しても以下のエラーが出てきます。
The parameter app_id is required
###該当のソースコード
ruby
1//config/initializers/devise.rb 2config.omniauth :facebook, ENV['FACEBOOK_APP_ID', ENV['FACEBOOK_APP_SECRET'] 3
ruby
1//.env 2FACEBOOK_APP_ID="123456789" 3FACEBOOK_APP_SECRET="123456789abcdefg"
ruby
1// models/user.rb 2 3class User < ApplicationRecord 4 # Include default devise modules. Others available are: 5 # :confirmable, :lockable, :timeoutable and :omniauthable 6 attr_accessor :login 7 devise :database_authenticatable, :registerable, 8 :recoverable, :rememberable, :trackable, :validatable, :omniauthable 9 10 11 def self.find_for_facebook_oauth(auth) 12 13 user = User.where(provider: auth.provider, uid: auth.uid).first 14 unless user 15 user = User.create( name: auth.extra.raw_info.name, 16 provider: auth.provider, 17 uid: auth.uid, 18 email: auth.info.email, 19 token: auth.credentials.token, 20 password: Devise.friendly_token[0,20] ) 21 end 22 user 23 end 24end
ruby
1// app/controllers/users/omniauth_callbacks_controller.rb 2 3class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 4 5 def facebook 6 @user = User.find_for_facebook_oauth(request.env["omniauth.auth"]) 7 8 if @user.persisted? 9 sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated 10 set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? 11 else 12 session["devise.facebook_data"] = request.env["omniauth.auth"] 13 redirect_to new_user_registration_url 14 end 15 end 16 17 18end
ruby
1//config/routes.rb 2 3Rails.application.routes.draw do 4 5 devise_for :users, controllers: { 6 omniauth_callbacks: "users/omniauth_callbacks" 7 } 8 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 9 10 get '/auth/:provider/callback', to: 'users#create', as: :auth_callback 11 get '/auth/failure', to: 'users#auth_failure', as: :auth_failure 12end
facebookアプリ情報
Site URL: http://hoge.com:3000/
Valid OAuth redirect URIs: http://hoge.com:3000/auth/facebook/callback
一通り試してみて動かず、Facebookアプリの登録で何か別に設定が必要かなど教えていただきたいです。。。