Venmo / Oauth缺少参数:client_id。,代码:241

时间:2014-04-16 15:59:28

标签: ruby-on-rails ruby-on-rails-4 devise omniauth venmo

我正在使用oauth尝试根据this指南尝试通过venmo登录。这不是官方和venmo文档甚至不显示ruby的代码示例。

起初,我甚至无法看到venmo登录。我删除了初始化程序中id和secret周围的ENV和括号,然后我就可以看到登录了。当我提交它并且它回击回来时我得到这个错误:(我认为它无休止地重试......我必须手动关闭服务器)

{"error": {"message": "Missing argument: client_id.", "code": 241}}
I, [2014-04-16T11:49:48.124423 #47700]  INFO -- omniauth: (venmo) Callback phase initiated.
E, [2014-04-16T11:49:48.345202 #47700] ERROR -- omniauth: (venmo) Authentication failure!       invalid_credentials: OAuth2::Error, {"message"=>"Missing argument: client_id.", "code"=>241}: 

这是我的路线:

get 'users/auth/venmo/callback' => 'omniauth_callbacks_controller#create'

宝石:

gem 'devise'
gem 'omniauth'
gem 'omniauth-venmo'

我在初始化器/ omniauth.rb

中有这个
Rails.application.config.middleware.use OmniAuth::Builder do
   provider :venmo, 'id', 'secret', :scope => 'access_feed,access_profile,access_friends,make_payments'   
end

这是我的回调控制器

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def venmo
    @user = User.find_for_oauth(env["omniauth.auth"], current_user)
    raise
    if @user.persisted?
        sign_in_and_redirect root_path, :event => :authentication
        set_flash_message(:notice, :success, :kind => "Venmo") if is_navigational_format?
    else
        session["devise.venmo_uid"] = env["omniauth.auth"]
        redirect_to new_user_registration_url
    end
end

protected

def auth_hash
    request.env['omniauth.auth']
end 

我有初始化器/ devise.rb

   require 'omniauth-venmo'
   config.omniauth :venmo, "KEY", "SECRET"

- 当然填写了值。我很感激帮助...... 谢谢!!

更新:我已将此推送到github存储库,我的一位同事将其拉出来。他没有得到同样的错误。这是什么原因..? here is the output

2 个答案:

答案 0 :(得分:4)

@ Peege151 ...我创建了一个使用设计集成的工作解决方案,如下所示。我的代码如下,用于参考目的。我不是说这是提出的问题的确切解决方案,但这可能有所帮助,因为我得到它的工作

宝石:

gem 'rails 3.2.14' # Important~
gem 'devise'
gem 'omniauth'
gem 'omniauth-venmo'

我没有在初始化器中创建omniauth.rb ....而是我在devise.rb中添加了配置,因为你想要它与设计

my devise.rb:

require "omniauth-venmo"
config.omniauth :venmo, '--Your APP KEY -- ', '-- App Secret--',{:client_options => {:ssl => {:verify => false}}}

以上我已将SSL验证设置为false,如果您想要使用(:verify =&gt; true)启用SSL。

这是我的回调控制器代码:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def venmo 
   @user = User.find_for_oauth(request.env["omniauth.auth"], current_user) 
   if @user.persisted? 
     sign_in_and_redirect @user, :event => :authentication 
     set_flash_message(:notice, :success, :kind => "Venmo") if is_navigational_format? 
   else 
     session["devise.twitter_uid"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url
   end
  end  
end

User.rb代码:

class User < ActiveRecord::Base
  TEMP_EMAIL = 'change@me.com'
  TEMP_EMAIL_REGEX = /change@me.com/ 
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :provider , :uid 
  devise :omniauthable

  def self.find_for_oauth(auth, signed_in_resource=nil) 
      user = User.where(:provider => auth.provider, :uid => auth.uid).first
      if user 
        return user
      else 
        registered_user = User.where(:email => auth.info.email).first 
        if registered_user 
          return registered_user
        else 
          user = User.create(name:auth.extra.raw_info.name,
                          provider:auth.provider,
                          uid:auth.uid,
                          email:auth.info.email.blank? ? TEMP_EMAIL : auth.info.email,
                          password:Devise.friendly_token[0,20],
                        )        
         end          
      end
      user
    end
  end

这是我的设计和回调路线.rb:

 devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
 get '/auth/venmo/callback' => 'users/omniauth_callbacks#venmo'

登录页面链接:

<%= link_to "Sign in with Venmo", user_omniauth_authorize_path(:venmo) %> 

截图:

enter image description here

答案 1 :(得分:2)

我不确定这里的具体问题,但有一点需要注意的是它看起来像是在打造一个裸露的网址而不是api.venmo.com/v1/,这是我们的最新版本。首先尝试,然后我们可以在那里工作。