With VK authentication, everything works, now it fails with Facebook omniauth_controller.rb
class OmniauthController < ApplicationController skip_before_action :require_user before_action :current_user_resorces def create if @user @account[user: @user] else @user = User.create(auth_params) @account[user_id: @user] end binding.pry @account.save session[:current_user_id] = @user.token redirect_to root_path end def current_user_resorces @account = Account.find_or_create_by(uid: auth_hash[:uid], provider: auth_hash[:provider], email: auth_hash[:info][:email]) @user = User.find_by(email: auth_hash[:info][:email]) end private def auth_params password = "#{rand(100)}_sample_password_#{rand(100)}" { first_name: auth_hash[:extra][:raw_info][:first_name], last_name: auth_hash[:extra][:raw_info][:last_name], token: auth_hash[:credentials][:token], email: auth_hash[:info][:email], password: password, password_confirmation: password } end protected def auth_hash request.env['omniauth.auth'] end end omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, ENV['facebook_key'], ENV['facebook_secret'], scope: 'email' provider :vkontakte, ENV['vk_key'], ENV['vk_secret'], scope: 'email' end response
From: /home/andrey/dev/note_work/app/controllers/omniauth_controller.rb @ line 12 OmniauthController#create: 5: def create 6: if @user 7: @account[user: @user] 8: else 9: @user = User.create(auth_params) 10: @account[user_id: @user] 11: end => 12: binding.pry 13: @account.save 14: session[:current_user_id] = @user.token 15: redirect_to root_path 16: end [1] pry(#<OmniauthController>)> auth_hash => {"provider"=>"facebook", "uid"=>"1595189064132754", "info"=>{"name"=>"Андрей Шостик", "image"=>"http://graph.facebook.com/1595189064132754/picture"}, "credentials"=> {"token"=> "CAASSzI1FNZBIBALpKPJoXXyQuZB0697rVBdgVXmpgrY6PsQRFWUTBjbT01hgzygVFw5uwxFT7keFEiwzaWWHfm50mMINWwcmQlofoEYkFDD6eUKMyhSUI4KvIlT7Uzx5sHZBiBvhxqIYEFUlwrKp4SGLTCrpnbdKY8jZA1AC1ZB4qU1V2ShluEe5Ehi0mfCTyZA4FXlJdysAZDZD", "expires_at"=>1465980629, "expires"=>true}, "extra"=>{"raw_info"=>{"name"=>"Андрей Шостик", "id"=>"1595189064132754"}}} [2] pry(#<OmniauthController>)> @user => #<User:0x007f16786db880 id: nil, login: nil, email: nil, first_name: nil, last_name: nil, password_digest: "$2a$10$KJJJQ7.Pn5UDVLQ.yVXeDed7tUGdbiiSI.91Vq8FtvXmFQUUxEb4O", token: "CAASSzI1FNZBIBALpKPJoXXyQuZB0697rVBdgVXmpgrY6PsQRFWUTBjbT01hgzygVFw5uwxFT7keFEiwzaWWHfm50mMINWwcmQlofoEYkFDD6eUKMyhSUI4KvIlT7Uzx5sHZBiBvhxqIYEFUlwrKp4SGLTCrpnbdKY8jZA1AC1ZB4qU1V2ShluEe5Ehi0mfCTyZA4FXlJdysAZDZD", created_at: nil, updated_at: nil> [3] pry(#<OmniauthController>)>