omniauth OAuthException & OAuth::未经授权
我已经安装了omniauth 1.0。我还有 oauth-0.4.5、oauth2-0.5.1、omniauth-facebook-1.0.0、omniauth-twitter-0.0.6。
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, ENV['167257285348131'], ENV['c8c722f697scb2afcf1600286c6212a9'], :scope => 'email,offline_access,read_stream', :display => 'popup'
provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI']
end
session_controller.rb
class SessionsController < ApplicationController
require 'omniauth-facebook'
require 'omniauth-twitter'
require 'omniauth'
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
self.current_user = @user
redirect_to '/'
end
def auth_hash
request.env['omniauth.auth']
end
end
我还补充一下 '全能' 'omniauth-facebook' 'omniauth-twitter' gems 到 gemfile
有两个问题:
- 当我去 http://localhost:3000/auth/facebook 时我明白了 { “错误”: { "message": "缺少 client_id 参数。", “类型”:“OAuthException” } 和
链接 graph.facebook.com/oauth/authorize?response_type=code&client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&parse=query&scope=email%2Coffline_access% 2Cread_stream&display=popup 并且没有 client_id!!!
- 当我转到 http://localhost:3000/ auth/twitter 我收到 OAuth::Unauthorized
401 Unauthorized 有
什么想法吗?
I have installed omniauth 1.0. Also I have oauth-0.4.5, oauth2-0.5.1, omniauth-facebook-1.0.0, omniauth-twitter-0.0.6.
omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :facebook, ENV['167257285348131'], ENV['c8c722f697scb2afcf1600286c6212a9'], :scope => 'email,offline_access,read_stream', :display => 'popup'
provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI']
end
session_controller.rb
class SessionsController < ApplicationController
require 'omniauth-facebook'
require 'omniauth-twitter'
require 'omniauth'
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
self.current_user = @user
redirect_to '/'
end
def auth_hash
request.env['omniauth.auth']
end
end
Also I add
'omniauth'
'omniauth-facebook'
'omniauth-twitter' gems to gemfile
There are two problems:
- When I go http://localhost:3000/auth/facebook I get
{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException"
}
}
And the link graph.facebook.com/oauth/authorize?response_type=code&client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&parse=query&scope=email%2Coffline_access%2Cread_stream&display=popup
And there is no client_id!!!
- When I go to http://localhost:3000/auth/twitter I get OAuth::Unauthorized
401 Unauthorized
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Alex D. 是正确的,因为 ENV[] 打破了它。要创建omniauth.rb,以便它在不同的环境中使用不同的密钥,只需将:
放在omniauth.rb中
,然后在您的环境配置文件(config/environments/development.rb等)中放入您想要用于该环境的密钥。
配置/环境/开发.rb:
配置/环境/生产.rb:
Alex D. is correct in that the ENV[] breaks it. To create omniauth.rb so that it uses different keys in different environments just put:
in omniauth.rb
and then in your environment config files (config/environments/development.rb, etc.) put the key you want to use for that environment.
config/environments/development.rb:
config/environments/production.rb:
ENV['something']
会查找您的环境变量中的“something”,因此它会期望
something='12345'
那样进行操作
所以您应该像检查
和更新 你的配置
如果你使用heroku的话
ENV['something']
looks into your environment vars for "something", so it would expect
something='12345'
so you should do it like that
check with
and update your config
if you use heroku
omniauth 1.0 中发生了重大更改 - https://github.com/intridea/omniauth
我会尝试将omniauth恢复为0.3.2:
或者如果您使用捆绑器,请在您的Gemfile中:
There have been breaking changes made in omniauth 1.0 - https://github.com/intridea/omniauth
I would try reverting omniauth to 0.3.2:
or if you're using bundler, in your Gemfile: