阶段:
我有一个Rails应用程序,它应该使用他们的Twitter帐户验证用户,所以我使用Omniauth-Twitter gem。
我已在dev.twitter.com
中配置了一个应用,启用了Sign in with twitter
标记,并获得了consumer_key
和consumer_secret
。
我正在关注本指南https://github.com/arunagw/omniauth-twitter#readme
在Rails应用程序中,我配置了一些文件:
config/initializers/omniauth.rb
:
Rails.application.config.middleware.use OmniAuth::Builder do
# Twitter consumer data
CONSUMER_KEY='xxxxxxxxxxxxxxxxx'
CONSUMER_SECRET='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
provider :twitter, CONSUMER_KEY, CONSUMER_SECRET
end
sessions_controller.rb
看起来像:
class SessionsController < ApplicationController
def create
raise request.env["omniauth.auth"].to_yaml
end
end
applications.html.erb
布局:
<div id="user_nav">
<%= link_to "Sign in with Twitter", "/auth/twitter" %>
</div>
所以除了当我在Sign in with Twitter
链接上进行clic时,我提出了一个异常,显示我的身份验证数据或请求我进行Twitter自动化。
问题:
而不是这个,它返回这个:
OAuth::Unauthorized (401 Unauthorized):
oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (0.0.15) lib/omniauth/strategies/twitter.rb:63:in `request_phase'
omniauth (1.1.3) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.3) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.3) lib/omniauth/builder.rb:48:in `call'
这里有什么问题?