简体   繁体   English

Rails Omniauth缺少必需的参数:代码

[英]Rails Omniauth missing required parameter: code

Running rails 3.2.18 on c9.io, and I have the gems omniauth and omniauth-google-oauth2 installed. 在c9.io上运行rails 3.2.18,并且安装了gem omniauth和omniauth-google-oauth2。 I ran into a problem where I would get a CSRF error on the callback, and it sounded like adding "provider_ignores_state: true" to the params would prevent that, at least for testing and development. 我遇到了一个问题,我将在回调中收到CSRF错误,这听起来像在参数中添加“ provider_ignores_state:true”会阻止这种情况,至少对于测试和开发而言。 It did get rid of the CSRF error, but now there is a new error: 它确实摆脱了CSRF错误,但现在有了一个新错误:

OAuth2::Error

invalid_request: Missing required parameter: code
{
  "error" : "invalid_request",
  "error_description" : "Missing required parameter: code"
}

my config/initializers/omniauth.rb 我的配置/初始化/ omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, "clientID", "clientSecret",
    scope: 'profile', image_aspect_ratio: 'square', image_size: 48, access_type: 'online', name: 'google', provider_ignores_state: true
end

Top few lines from the trace: 跟踪的前几行:

oauth2 (1.0.0) lib/oauth2/client.rb:113:in `request'
oauth2 (1.0.0) lib/oauth2/client.rb:138:in `get_token'
oauth2 (1.0.0) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
omniauth-oauth2 (1.3.1) lib/omniauth/strategies/oauth2.rb:93:in `build_access_token'
omniauth-google-oauth2 (0.2.6) lib/omniauth/strategies/google_oauth2.rb:77:in `custom_build_access_token'

EDIT: Adding the versions for the gems 编辑:添加宝石的版本

/usr/local/rvm/gems/ruby-1.9.3-p547/gems/omniauth-1.2.2
/usr/local/rvm/gems/ruby-1.9.3-p547/gems/omniauth-google-oauth2-0.2.6

So the problem was in the view! 因此问题出在视图中! I was trying to use /auth/google/callback when it should have just been /auth/google. 我本来应该是/ auth / google的时候尝试使用/ auth / google / callback。 Took way too long to figure that one out... 花了太长时间才弄清楚那个...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM