帮助推特回声 &我的 rails 应用程序中的 oauth [英] Help with twitter echo & oauth in my rails app
问题描述
我的应用要求用户使用他们的推特账号登录!我正在使用 tardate oauth lib(来自 Paul Gallagher).这很好用.我想为我的网站创建一个 API(实际上是用户身份验证部分).Twitter Basic Auth 已被弃用,现在 twitter 使用 twitter echo.如果用户想通过我的应用程序中的 api 上传文件,他必须在他的请求中包含上述标头.所以,我的问题是:(我想标题直接命中 twitter api,twitter 在我的 url 中返回响应..这是正确的吗?)
My app requires from users to login with their twitter acount! I am using tardate oauth lib (from Paul Gallagher). That works fine. I wanna create an API for my website (actually the user authentication part). Twitter Basic Auth has been deprecated and now twitter uses twitter echo. If a user wants to upload a file via api in my app, he must include in his request the above header. So, my problem is: (i suppose that header hits twitter api directly and twitter returns in my url the response..is this right?)
我的应用如何处理 Twitter 响应?包含用户信息(或否定响应 401)的 json,以便继续上传或不上传.类似于 twitpic API 的功能.(http://dev.twitpic.com/docs/2/upload/) 或类似的服务.
how my app can handle the twitter response? json that contains user's info (or a negative response 401), in order to continue the uploading or not. Something like the twitpic API does.(http://dev.twitpic.com/docs/2/upload/) or by similar services.
curl -v -H 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json' -H 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/",
oauth_consumer_key="yTrEIQH6jhtmLUypg8T5", oauth_signature_method="HMAC-SHA1",
oauth_token="514797-YuI8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWTyu",oauth_timestamp="1271323750",
oauth_nonce="oYu6nMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7U9Y",
oauth_version="1.0", oauth_signature="CV4bTfE7Rs9J1kafTGwufLJdspo%3D"' -F "file=@/path/to/file" http://localhost:3000/api/upload.xml
我的 def 上传目前适用于通过 api 进行简单上传.没有用户信息.但是这样我的应用程序不知道文件所有者!
my def upload currently works for a simple upload via api. Without a user info. But in this way my app doesn't know the file owner!
def upload
file = File.new
file.file = params[:file]
# ... extra code
respond_to do |format|
if file.save
format.xml { render :xml => file, :status => :created, :location => file }
else
format.xml { render :xml => file.errors, :status => :unprocessable_entity }
end
end
end
您知道编码逻辑如何吗?
Do you have any idea how can be the coding logic?
任何帮助将不胜感激:-)
Any help will be highly appreciated :-)
推荐答案
我认为最好的方法是抓取标题然后使用 Patron..
I think that the best way is to grab headers and then use Patron..
auth_headers = request.headers["X-Verify-Credentials-Authorization"]
Patron 可以向 https://api.twitter.com/1/account/verify_credentials.json
发出 post 请求,然后检查响应状态!
Patron can make a post request to https://api.twitter.com/1/account/verify_credentials.json
and then check the resp status!
这篇关于帮助推特回声 &我的 rails 应用程序中的 oauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!