pelle / oauth-plugin

Rails plugin for OAuth
http://stakeventures.com/articles/2009/07/21/consuming-oauth-intelligently-in-rails
MIT License
716 stars 216 forks source link

consumer_token saved with user_id=nil #84

Closed jp closed 12 years ago

jp commented 12 years ago

Hi,

I'm using OAuth-plugin and devise for Linkedin API. I (should) have set up correctly the devise aliases in oauth_consumers_controller.rb : almost everything is working fine.

When I grant the rights to my linkedin account on this page : http://localhost:2002/oauth_consumers/linkedin , the consumer_tokens is saved with user_id=nil

In all the other request, the current_user is correctly retrieved, but not in the insert. I believe this is a kind of stupid error, but I can't figure where to correct this.

Here is the log from the server :

Started GET "/oauth_consumers/linkedin/callback?&oauth_token=7XXXXXXXXX735&oauth_verifier=17860" for 127.0.0.1 at 2011-09-20 15:27:39 +1200 Processing by OauthConsumersController#callback as HTML Parameters: {"oauth_token"=>"7XXXXXXXXXXXXXXa735", "oauth_verifier"=>"17860", "id"=>"linkedin"} User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 LinkedinToken Load (0.2ms) SELECT "consumer_tokens".* FROM "consumer_tokens" WHERE "consumer_tokens"."type" IN ('LinkedinToken') AND "consumer_tokens"."user_id" = 1 LIMIT 1 CALLBACK LinkedinToken Load (0.3ms) SELECT "consumer_tokens".* FROM "consumer_tokens" WHERE "consumer_tokens"."type" IN ('LinkedinToken') AND "consumer_tokens"."user_id" = 1 AND "consumer_tokens"."token" = '699XXXXXXXXXXXX3b0' LIMIT 1 CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 SQL (13.1ms) INSERT INTO "consumer_tokens" ("created_at", "secret", "token", "type", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Tue, 20 Sep 2011 03:27:40 UTC +00:00], ["secret", "5f27XXXXXXXXXXX6c40"], ["token", "699XXXXXXXXXXXXdb3b0"], ["type", "LinkedinToken"], ["updated_at", Tue, 20 Sep 2011 03:27:40 UTC +00:00], ["user_id", nil]] Redirected to http://localhost:2002/

jpoday commented 12 years ago

I had the same problem. Here's a fix https://github.com/pelle/oauth-plugin/issues/88

jp commented 12 years ago

Great, I will give some feedback on this as soon as possible. Thanks !

jp commented 12 years ago

Found the solution here : http://unhandledexpression.com/2011/06/28/rails-and-oauth-plugin-part-2-the-consumer/#comment-205

You should add this to your ApplicationController:

def current_user=(user) current_user = user end