My favorites | Sign in
Project Home Wiki
Search
for
RequestToken  
How the RequestToken api works
Updated Feb 4, 2010 by pel...@gmail.com

Introduction

The RequestToken is used for the Authentication phase of the OAuth protocol

See Spec

This is only used from the ConsumerService side.

RequestToken lifecycle

  1. ConsumerService Request a RequestToken from the ServiceProvider using Consumer
  2. Redirect user to the ServiceProvider's AuthorizationUrl with an appended token
  3. User authorizes the RequestToken
  4. ConsumerService exchanges RequestToken for an AccessToken

Contains

  • token - the actual token string
  • secret - a secret string used for signing requests

Creation

You ask a Consumer object to request the token from the ServiceProvider

@request_token=@consumer.get_request_token

Authorization

Redirect the user to the authorization_url:

redirect_to @request_token.authorization_url

Exchange for AccessToken

Once the user is redirected back to the callback url you can exchange it:

@access_token=@request_token.get_access_token
Comment by veluraja...@gmail.com, Oct 11, 2010

I followed these steps,, but while executing this step @access_token=@request_token.get_access_token

I found the error like "INVALID authorization"

can anybody help me .

Comment by kingandr...@gmail.com, Nov 3, 2010

i have similar problem, but error is `token_request': 401 Unauthorized (OAuth::Unauthorized) in line 139 on consumer.rb

Comment by toine...@gmail.com, Jan 3, 2011

Same here: 401 Unauthorized

file: consumer.rb location: token_request line: 217

Works in 0.4.3, fails in 0.4.4

Comment by klebersh...@gmail.com, Jan 17, 2011

same error as @toine: 401 Unauthorized

Comment by sdepab...@gmail.com, Jan 17, 2011

Same error, 401 Unauthorized, working with version 0.3.4 and 0.4.3

Comment by t...@wishpot.com, Aug 22, 2011
Comment by don.pott...@gmail.com, Dec 25, 2011

I successfully implemented a Rails 3.0.9 app as an OAuth provider using the oauth and oauth-plugin gems. However, to Rails 3.1.3, I'm receiving an 401 Unauthorized error when attempting to get the request token. I'm not sure whether it's an incompatibility with the gem or an issue with Rails 3.1.3.

I've been testing locally with the following:

- Rails 3.1.3 - oauth (0.4.5) - oauth-plugin (0.4.0.rc2)

> Consumer Key: BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm Consumer

> Secret: eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw

> Request Token URL: http://localhost:3000/oauth/request_token

> Access Token URL: http://localhost:3000/oauth/access_token

> Authorize URL: http://localhost:3000/oauth/authorize

In the console:

ruby-1.9.2-p290 :003 > @consumer = OAuth::Consumer.new
"BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm", "eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw", {:site => "http://localhost:3000"}
=> #<OAuth::Consumer:0x007fe93d5bcdf8 @key="BkdI1PnzRuvKDw2Qs1wVxtDrtvmqhUgeXLwNpNtm",
@secret="eCY7JFk4vK6IeWXVq7yS3OMVT1XKpVOWOImsy3iw", @options={:signature_method=>"HMAC-SHA1",
:request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>"http://localhost:3000"}>

ruby-1.9.2-p290 :004 > @consumer.get_request_token OAuth::Unauthorized: 401 Unauthorized
from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/oauth-0.4.5/lib/oauth/consumer.rb:219:in `token_request' from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/oauth-0.4.5/lib/oauth/consumer.rb:139:in `get_request_token' from (irb):4 from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start' from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start' from /Users/donpottinger/.rvm/gems/ruby-1.9.2-p290@rails3_1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'

I've tried downgrading the oauth and oauth-plugin gems, but that doesn't seem to help. The same setup seems to work as expected in Rails 3.0.9. Any help would be greatly appreciated.

Comment by miguelmi...@gmail.com, Feb 3, 2012

same issue in rails3.2 oauth_plugin 0.4.0.rc2


Sign in to add a comment
Powered by Google Project Hosting