OAuth with Rails help getting going

2 views
Skip to first unread message

Rajinder Yadav

unread,
Aug 13, 2010, 8:35:22 PM8/13/10
to twitter-deve...@googlegroups.com
Hello,

I'm not having success with the following code, I get a "Sorry, page
doesn't exist!" webpage. I am using the OAuth v0.4.1 gem. Your help and
guidance is very appreciated, thanks!

If I type the following out in IRB, it seems to work, but of course I
can't redirect from the shell.


class HomeController < ApplicationController

def index
@consumer = OAuth::Consumer.new( "bLXXXXXXXXI9szbXTJQnXKA",
"XXXXXXXXXXm41S6SYEy9uYR5oiAUxToPvQUlMd6g9A",
{ :site=>"https://api.twitter.com/oauth/request_token" } )

@request_token=@consumer.get_request_token

session[:consumer] = @consumer
session[:request_token] = @request_token

redirect_to @request_token.authorize_url
end

end

--
Kind Regards,
Rajinder Yadav

Rajinder Yadav

unread,
Aug 13, 2010, 11:22:08 PM8/13/10
to twitter-deve...@googlegroups.com
Hi I found by making the following change I now see the allow/deny page. However when I click on allow, I do not get redirected back to my callback page?



@consumer = OAuth::Consumer.new( "bLXXXXXXXXI9szbXTJQnXKA",
       "XXXXXXXXXXm41S6SYEy9uYR5oiAUxToPvQUlMd6g9A",
       :site=>"https://twitter.com",
       :request_token_path => "/oauth/request_token",
       :authorize_path     => "/oauth/authorize",
       :access_token_path  => "/oauth/access_token",
       :http_method => :get ) )


What I am seeing in the pin page, saying:

You've successfully granted access to XXXX_TestApp!
Simply return to XXXX_TestApp and enter the following PIN to complete the process.

How do I get Twitter to return back to my callback page on my site? My app type is correctly set to "browser".

Tom van der Woerdt

unread,
Aug 14, 2010, 9:20:44 AM8/14/10
to twitter-deve...@googlegroups.com

Hi,

You should send the oauth_callback parameter, as specified by the
documentation.

Tom

Rajinder Yadav

unread,
Aug 14, 2010, 1:21:37 PM8/14/10
to twitter-deve...@googlegroups.com
> You should send theoauth_callback parameter, as specified by the
> documentation.
>
> Tom
>
Hi Tom,

I have tired sending oauth_callback, made sure that my callback url
matches exactly the one specified in twitter app setting, something like
this:

redirect_to @request_token.authorize_url + "&oauth_callback=" +
CGI.escape("http://myhome.dnydns.org/callback")

I am testing the site from home using dynamic dns setup, would this be
causing the problem?
Also in the call to OAuth::Consumer.new, should the http_method be :get
or :post ?
I've also changed :site=>"https://twitter.com" to, :site =>
"https://api.twitter.com"
I'm still not sure what I am doing wrong and I feel like I am chasing my
tail!

Tom van der Woerdt

unread,
Aug 15, 2010, 1:13:58 PM8/15/10
to twitter-deve...@googlegroups.com

Hi Rajinder,

Sorry if you misunderstood my last message. You are supposed to send the
callback in your oauth_callback parameter. If you get the PIN page, then
you send "oob" - out-of-bands, as your oauth_callback.

http://tools.ietf.org/html/rfc5849#section-2.1
Section 2.1 of RFC 5849 (OAuth 1.0) specifies oauth_callback as REQUIRED
- so, you are probably already sending it (either that, or Twitter
doesn't follow the specifications).

Also, it is a part of Section 2.1 of the OAuth specification - the part
where the client talks to the server. The line you changed was Section
2.2 - the redirection part.

Tom

Rajinder Yadav

unread,
Aug 16, 2010, 3:01:58 AM8/16/10
to twitter-deve...@googlegroups.com
Hi Tom,

I finally figured it out, the examples for RoR using OAuth seem to be
stale. I was peeved at what seems to be a 'simple' process has to get so
complicated.

Reply all
Reply to author
Forward
0 new messages