在Omniauthable上设计错误的参数数量(13为2)

时间:2018-03-18 00:47:12

标签: ruby-on-rails devise

尝试按照本教程实施Google登录使用Devise进入我的rails应用:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

获取此错误: error

我的路线:

devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' }

Omniauthable控制器:app/controllers/users/omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def google_oauth2
    @user = User.from_omniauth(request.env["omniauth.auth"])
    puts @user
    if @user.persisted?
      sign_in_and_redirect @user
      set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?
    else
      puts "WENT INTO HERE---------"
      session["devise.google_data"] = request.env["omniauth.auth"]
      redirect_to root_path
    end
  end

  def failure
    redirect_to root_path
  end
end

User.rb

class User < ApplicationRecord

  devise :rememberable, :trackable,
         :omniauthable, omniauth_providers: %i[google_oauth2]




  # rubocop:disable Metrics/AbcSize
  def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.email = auth.info.email
      # user.password = Devise.friendly_token[0,20]
      user.first_name = auth.info.first_name
      user.last_name = auth.info.last_name
      user.image_url = auth.info.image # assuming the user model has an image
    end
  end
end

我从会话转储中找出了应用引用的13个参数:

warden.user.user.key: {"id"=>204, "uid"=>"*******", "first_name"=>"First name", "last_name"=>"last name", "provider"=>"google_oauth2", "image_url"=>"*****", "email"=>"***", "has_logged_in"=>false, "created_at"=>"2018-03-17T21:26:24.782Z", "updated_at"=>"2018-03-17T23:31:38.220Z", "admin"=>false}

但我不知道它来自何处或如何解决它

1 个答案:

答案 0 :(得分:0)

不确定问题是什么,但在关闭浏览器后,问题得到解决。所以它可能与我的缓存有关。