我在StackOverFlow中实现了几种不同的策略,但到目前为止,似乎都没有影响抛出的错误:
我正在关注
Ryan Bates的RC #241
当我点击"Sign-in with Twitter“的时候,我得到了错误信息。我继续将响应路由添加到
如下所示的文件:
**
:**
match 'auth/twitter/callback', to: 'user#update'认为错误可能是由回调函数引起的。同样的错误。A看看我的
如下所示:
Started GET "/auth/twitter" for 127.0.0.1 at 2014-09-16 18:52:08 -0600
(twitter) Request phase initiated.
OAuth::Unauthorized (401 Authorization Required):
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 (1.0.1) lib/omniauth/strategies/twitter.rb:60:in `request_phase'
omniauth (1.2.2) lib/omniauth/strategy.rb:215:in `request_call'
omniauth (1.2.2) lib/omniauth/strategy.rb:183:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'
...
script/rails:6:in `require'
script/rails:6:in `'
-e:1:in `load'
-e:1:in `'
So I know the issue is with the authentication with Twitter going out. Must be the KEY and SECRET, right?
Now, I have put the KEY and SECRET in as ENV[] variables, as direct strings to the environment/development.rb file, taken out the "ENV[]" variables, etc., as per suggestions found all over Stack.
My KEY and SECRET now reside in a custom configuration as discussed here...
config/initializers/social_media.rb:
TWITTER_CONFIG = YAML.load_file("#{::Rails.root}/config/twitter.yml")[::Rails.env]
The config/initializers/omniauth.rb file:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, TWITTER_CONFIG['app_id'], TWITTER_CONFIG['secret']
end
Any ideas on the ActionController: Exception caught OAuth::Unauthorized - 401 Authorization Required? This is probably a Noob error, but my Google-Fu is just Google-F'ed right now...发布于 2014-09-18 01:04:42
在经历了一夜的辛苦工作之后,我看了一眼回调URL
Twitter开发人员控制台
..。
省去了一些麻烦,别忘了设置这个。在RailsCast中没有直接提到这一点,尽管瑞安确实简单地略过了它。
当您设置回调URL时,不要只将
它不会起作用的。请改用:
http://127.0.0.1:3000/发布于 2021-03-01 04:19:08
在使用Rails 6应用程序时,我也遇到了同样的问题。
omniauth-twitter
和
设计
宝石
我添加了
和
致我的
Rails 6
应用程序,但当我尝试测试Twitter身份验证时,我遇到以下错误:
OAuth::Unauthorized 401 Authorization Required下面是我是如何解决这个问题的
我在我的Twitter开发者帐户中添加了以下回调URL:
http://localhost:3000/auth/twitter
http://localhost:3000/auth/twitter/callback
http://localhost:3000/users/auth/twitter
http://localhost:3000/users/auth/twitter/callback注意
:替换
使用您的实际
..。此外,
路线
用于回调URL的URL应与应用程序中设置的URL匹配。
资源
:
如何使用Devise、Omniauth和Ruby on Rails登录Twitter
仅此而已。
我希望这能有所帮助
https://stackoverflow.com/questions/25880781
复制相似问题