2014-04-16 41 views
2

我正在使用oauth嘗試通過基於this指南的venmo登錄。這不是官方的,venmo文檔甚至沒有用ruby顯示代碼示例。Venmo/Oauth缺失參數:client_id。,code:241

起初,我甚至看不到venmo登錄。我在初始化程序中刪除了ENV和括號中的id和括號,然後我可以看到登錄信息。當我提出和它打回電話我得到這個錯誤:(我認爲它重不休......我必須手動關閉服務器)

{"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

+0

如果加回'ENV [ 'VENMO_CLIENT_ID']'和'ENV [ 'VENMO_CLIENT_SECRET'] '然後在運行你的rails進程之前設置環境變量(例如'export VENMO_CLIENT_ID = whatever'在同一個終端中),那麼它是否工作? – agf

+0

我試過使用$ export,並且是的。仍然沒有骰子 – Peege151

+0

你會得到什麼錯誤? – agf

回答

4

@ Peege151 ...我用你所說的設計集成創建了一個工作解決方案..下面是我的代碼,將其用於參考目的。我不說這是對提出問題的確切解決方案,但是這可能會幫助,因爲我得到它的工作

寶石:

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

我沒有初始化創建omniauth.rb ....代替我添加配置devise.rb爲u希望它與設計

我devise.rb:

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

以上線我已設置SSL驗證爲假,,如果u希望能夠與(SSL:驗證=> true)。

這是我的回調控制器代碼:

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 = '[email protected]' 
    TEMP_EMAIL_REGEX = /[email protected]/ 
    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

+0

這裏的問題似乎是Devise不是最新的。按照最新標準,正在共享的Devise配置不正確。 – Tom

2

我不知道這裏的具體問題,但有一點要弄清的是,它看起來你打一個裸體網址,而不是api.venmo.com/v1/,這是我們的最新版本。先試試,然後我們可以從那裏開始工作。

+2

問題是我用的gem與rails 4不兼容,只有rails 3.2我應該早點想出來。 – Peege151