Twitter 3-legged authorization in Ruby -
i trying hand ruby on rails. have written code in sinatra. anyway question may not have framework. , question may sound novice question. playing twitter 1.1 apis , oauth first time.
i have created app xyz , registered twitter. got xyz's consumer key i.e., consumer_key , consumer secret i.e. consumer_secret. got xyz's own access token i.e access_token , access secret i.e. access_secret
xyz application type: read, write , access direct messages xyz callback url: http://www.mysite.com/cback , have checked: allow application used sign in twitter
what trying simple:
1) users come website , click link link twitter account
(not signin twitter)
2) opens twitter popup user grants permission xyz perform actions on his/her behalf
3) once user permits , popup gets closed, xyz app gets user's access token , secret , save in database.
4) xyz uses user's token , secret perform actions in future.
i may moron such work flow has been implemented on several thousands sites , twitter api documentations explain 3-legged authentication, still unable figure out.
i have read https://dev.twitter.com/docs/auth/3-legged-authorization , https://dev.twitter.com/docs/auth/implementing-sign-twitter unfortunately no ruby code found on internet explains step step example.
what link should used open twitter authentication page when user clicks link twitter account
. can here, write pseudo code pseduo credential above achieve goal beging till end of work flow? thanks.
update:
i started requesting request token
require 'oauth'
consumer = oauth::consumer.new(consumer_key, consumer_secret,
{ site: "https://twitter.com"})
request_token = consumer.get_request_token oauth_callback: 'http://www.mysite.com/tauth'
redirect_to request_token.authorize_url
i'm not familiar ror here workflow of oauth 'dance' need follow when user clicks button:
obtain unauthorized request token twitter sending request to
post https://api.twitter.com/oauth/request_token
signing request using consumer secret. done in background , transparent user.
you receive oauth_token , oauth_token_secret twitter.
redirect user to
https://api.twitter.com/oauth/authorize?oauth_token=[token_received_from_twitter]
using oauth token value received twitter in step 2.
when user authorizes app redirected callback url oauth_token , oauth_verifier appended url. i.e.
convert request token access token sending signed request along oauth_verifier to
post https://api.twitter.com/oauth/access_token
signing request consumer secret , token secret received in step 2.
if goes ok, receive new
oauth_token
,oauth_token_secret
twitter. access token user.using access token , secret received in step 6 can make twitter api calls on behalf the user sending signed requests appropriate api endpoints.
Comments
Post a Comment