gpt4 book ai didi

ruby-on-rails - Venmo/Oauth 缺少参数 : client_id.,代码:241

转载 作者:行者123 更新时间:2023-12-02 08:34:40 38 4
gpt4 key购买 nike

我正在使用 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 :

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

我在我的 initializers/omniauth.rb 中有这个

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

这是我的回调 Controller

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

结束

我有 initializers/devise.rb

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

——当然是填写了值。我将不胜感激帮助...谢谢!!

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

最佳答案

@Peege151...如您所说,我创建了一个具有设计集成的工作解决方案..下面是我的代码,供引用。我并不是说这是所提出问题的确切解决方案,但这可能会有所帮助,因为我已经开始工作了

gem :

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

我没有在初始化程序中创建 omniauth.rb ....而是我在 devise.rb 中添加了你想要的配置

我的设计.rb :

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

如果您想使用 (:verify => true) 启用 SSL,我已将 SSL 验证设置为 false。

这是我的回调 Controller 代码:

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

这是我的设计和回调 routes.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

关于ruby-on-rails - Venmo/Oauth 缺少参数 : client_id.,代码:241,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23114499/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com