“验证失败 - 客户端应用程序不能为空”使用 oauth-plugin 和 mongoid
一般来说,我对 Rails3 和 Ruby 很陌生,但我可能会遇到一个问题 Ruby oauth-plugin 本身的问题。我正在尝试使用 使用用户授权我的网络应用程序的逻辑的消费者部分 推特帐户。一切都已设置好,我将被重定向 到 Twitter 进行授权,但当用户重定向回来时 对于我的应用程序,当将令牌保存到 MongoDB数据库:
Mongoid::Errors::Validations in Oauth consumersController#callback
Validation failed - Client application can't be blank.
单步执行框架代码后,我可以看到Token 类期望 client_application_id 有一个值,但我没有 认为消费者令牌应该与 ClientApplication 相关联 模型?
需要注意的一件事是我正在使用 oauth-plugin 的最新分支,其中包括修复 by 3en for mongoid,我能让模型工作的唯一方法是 通过使用“referenced_in”而不是“embedded_in”。 我在这里做错了什么?
预先感谢,
Rob
应用程序跟踪:
app/models/consumer_token.rb:25:in `find_or_create_from_access_token'
app/controllers/oauth_consumers_controller.rb:16:in `callback'
部分完整跟踪:
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb: 234:in `fail_validate!'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb: 75:in `save!'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:90:in `create!'
vendor/ruby/1.8/gems/simple_oauth-0.1.4/lib/simple_oauth/core_ext/object.rb:6:in `tap'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:89:in `create!'
app/models/consumer_token.rb:25:in `find_or_create_from_access_token'
vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/models/consumers/token.rb:38:in `find_or_create_from_request_token'
vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/controllers/consumer_controller.rb:35:in `callback'
app/controllers/oauth_consumers_controller.rb:16:in `callback'``
I'm new to Rails3 and Ruby in general, but I may be running into an
issue with the Ruby oauth-plugin itself. I'm attempting to use the
consumer portion of the logic to authorize my web app with a user's
Twitter account. Everything is setup to the point that I'm redirected
to Twitter for the authorization, but when the user is redirected back
to my app, I receive an error when the token is being saved into the
MongoDB database:
Mongoid::Errors::Validations in Oauth consumersController#callback
Validation failed - Client application can't be blank.
After stepping through the framework code, I can see that the Token
class is expecting client_application_id to have a value, but I didn't
think a consumer token should be associated with a ClientApplication
model?
One thing to note is I'm using the latest branch of oauth-plugin which includes fixes
by 3en for mongoid, and the only way I can get the models to work is
by using 'referenced_in' instead of 'embedded_in'.
What am I doing wrong here?
Thanks in advance,
Rob
Application trace:
app/models/consumer_token.rb:25:in `find_or_create_from_access_token'
app/controllers/oauth_consumers_controller.rb:16:in `callback'
Partial full trace:
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb: 234:in `fail_validate!'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/persistence.rb: 75:in `save!'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:90:in `create!'
vendor/ruby/1.8/gems/simple_oauth-0.1.4/lib/simple_oauth/core_ext/object.rb:6:in `tap'
vendor/ruby/1.8/gems/mongoid-2.0.0.rc.7/lib/mongoid/relations/referenced/many.rb:89:in `create!'
app/models/consumer_token.rb:25:in `find_or_create_from_access_token'
vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/models/consumers/token.rb:38:in `find_or_create_from_request_token'
vendor/ruby/1.8/bundler/gems/oauth-plugin-f805e8c359b1/lib/oauth/controllers/consumer_controller.rb:35:in `callback'
app/controllers/oauth_consumers_controller.rb:16:in `callback'``
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明我错误地遵循了文档。我的 User 类错误地引用了错误的 oauth 类。从头开始设置解决了我的问题。
It turns out I followed the docs incorrectly. My User class was incorrectly referencing the wrong oauth class. Starting from scratch with the setup fixed my issue.