Skip to content

Using 3 legged OAuth

jeremytregunna edited this page Feb 13, 2012 · 1 revision

Authorizing with OAuth

NOTE: These instructions are currently non-functional

In order to use ruby-trello in a case where you need 3-legged OAuth, one has to set things up a bit differently. For instance, where you set up your OAuthPolicy, it would look like this instead:

OAuthPolicy.consumer_credentail = OAuthCredential.new 'public_key', 'secret'
OAuthPolicy.return_url          = 'https://your.site.com/some_action'
OAuthPolicy.callback            = Proc.new do |request_token|
  DB.save(request_token)
  redirect_to request_token.authorize_url
end

When the user has authorized the request token, they'll be redirected back to your application via a POST message sent to the URL you store in OAuthPolicy.return_url. That action might look like this:

def some_action
  request_token = DB.where(:key => params[:key] && :secret => params[:secret]).first
  access_token = request_token.get_access_token
  OAuthPolicy.token = OAuthCredential.new access_token.key, access_token.secret
  DB.save(access_token)
end
Clone this wiki locally