开发者

'Validation failed - Client application can't be blank' using oauth-plugin and mongoid

开发者 https://www.devze.com 2023-02-11 09:03 出处:网络
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

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 sho开发者_运维问答uld 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'``


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号