我已经安装了omniauth 1.0。我也有oauth-0.4.5,oauth2-0.5.1,omniauth-facebook-1.0.0,omniauth-twitter-0.0.6。omniauth OAuthException&OAuth ::未授权
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' 'omniauth Facebook的' “omniauth,Twitter的宝石的Gemfile
有两个问题:
- 当我去http://localhost:3000/auth/facebook我得到“ { ”error“:{ ”message“:”Missing client_id parameter。“, ”type“:”OAuthException“ } }
和连杆graph.facebook.com/oauth/authorize?response_type=code & CLIENT_ID = & REDIRECT_URI = HTTP%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback &解析=查询& scope = email%2Coffline_access%2Cread_stream & display = popup 而且没有client_id !!!
- 当我去http://localhost:3000/auth/twitter我得到的OAuth ::未经授权
401未授权
任何想法?
你解决facebook的错误更新你的配置
?如果是这样,我可以解决这个问题吗?我收到相同的错误消息。它可以解决,如果我手动添加client_id查询字符串参数 – Vina
@Vina ENV []打破它。尝试仅使用“”。例如:提供者:Facebook,'167257285348131','c8c722f697scb2afcf1600286c6212a9' –
谢谢,它的工作!看来我还需要重启webrick。 :D – Vina