Open 3en opened 13 years ago
Okay, I managed to work it out.
There are two things that I believe is needed to make everything word:
1) Call back needs to be in /app/controllers/oauth_consumers_controller.rb def callback super end
2) Mongoid Queries in ConsumerToken in the class find_or_create_from_access_token need to be rewritten (in the file: oauth-plugin/lib/ generators/mongoid/oauth_consumer_templates/consumer_token.rb)
user.consumer_tokens.first(:conditions=>{:_type=>self.to_s,:token=>access_token.token}) ||
# New - Line 24
user.consumer_tokens.where(:_type=>self.to_s,:token=>access_token.token).first
And also from the same file
# Old - Line 29
user = User.first(:conditions=>{:_type=>self.to_s,"consumer_tokens.token"=>access_token.token})
# New - Line 29
user = User.where("consumer_tokens._type"=>self.to_s,"consumer_tokens.token"=>access_token.token).first
The "where" queries use what's called the Criteria API in Mongoid, which according to the documentation is "preferred method of querying the database" http://mongoid.org/docs/querying/
I will attempt to fork, patch, commit, push these changes. This is the first time I will be submitting a change to a gem :-)
Could you confirm that the callback method in oauth_consumer_controller is necessary? Can't think whats the best way to fix this, but it works for me.
Also I've just come across another issue. Need to clarify if you want ConsumerToken model to be embedded into the User model or referenced instead. Referencing works more like the traditional associations in SQL databases (data kept in separate collection/table).
Looks like having ConsumerToken referenced instead of embedded will work better as it means less code differing from the ActiveRecord implementation. But if you want it to be an embedded association to User then stuff like load_consumer in OauthConsumersController class needs to be overwritten for Mongoid.
I think embedded is the best case. But it could be done in a non embedded version.
I changed the mongoid generator to hopefully fix the issue you're seeing. Could you please test it:
https://github.com/pelle/oauth-plugin/commit/f805e8c359b18bd0254eaa774171ff7938ee8165
As the fix is in the generator you can just paste this over your existing consumer token:
I noticed this issue appears in 0.4.0 pre-3 and in 0.4.0 pre-4 with Mongoid. For debugging purposes I am using 0.4.0 pre-4.
I destroyed and re-generated oauth_consumer
The following error occurs even with the newly generated oauth_consumer_controller:
If I add (to oauth_consumer_controller):
The error results in:
Also just to double check as I belive this is not documented anywhere but looking at the generated ConsumerToken model I have defined the Mongoid relationship in User as "embeds_many :consumer_tokens". I believe this is right.
Any idea what's causing this. I believe it's only a problem since 0.4.0 pre-3