本文介绍了Devise,Omniauth和Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用devise和omniauth的Rails 3应用程序,并遵循,它对Facebook帐户有效,但是当我尝试添加Twitter auth时,我获得了401未授权响应。为了跟踪问题,我将api.twitter.com的URL转换为http并转储了网络流量,它看起来像/ oauth / access_token两次。第一次获得200响应,第二次给出401.在它之间,它使用GET /1/account/verify_credentials.json方法成功获取了经过身份验证的用户的用户信息。我不明白为什么代码第二次调用access_token方法。



在我的config / initializers / devise.rb文件中我添加了:

  config.omniauth:twitter,consumer_key,consumer_secret

除了上面的Omniauth概述页面中列出的其余代码。



我还添加了一个twitter方法我的OmniauthCallbacksController,但它从来没有被调用由于401。



任何帮助将不胜感激。

解决方案

尝试在dev.twitter.com上的应用程序设置中填写回调URL。应该是这样的:



回调URL


I'm working on a Rails 3 app that uses devise and omniauth and followed the examples given in https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview and it worked well for Facebook accounts, but when I tried adding Twitter auth, I get a '401 Unauthorized' response. To track the problem down I switched the URL for api.twitter.com to http and dumped the network traffic and it looks like it's POSTing to /oauth/access_token twice. The first time I get a 200 response, the second gives the 401. In between it successfully gets user info for the authenticated user using 'GET /1/account/verify_credentials.json' method. I don't understand why the code calls the access_token method the second time.

In my config/initializers/devise.rb file I added:

config.omniauth :twitter, "consumer_key", "consumer_secret"

in addition to the rest of the code outlined in the Omniauth overview page above.

I also added a 'twitter' method in my OmniauthCallbacksController, but it never gets called due to the 401.

Any help would be much appreciated.

解决方案

Try with filling Callback URL in settings of your application on dev.twitter.com. Should be something like that:

Callback URL http://yousite.com/auth/twitter/callback

这篇关于Devise,Omniauth和Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 13:30