RT.求指导,很急~~ 一般 devise.rb 中只能配置一个 provider :weibo
@suupic 不是换名字,而是同时添加 2 个相同的 比如 provider :weibo, key,secret provider :weibo, key,secret
devise.rb
config.omniauth :weibo, :setup => SETUP_PROC
SETUP_PROC = lambda do |env|
if Rack::Request.new(env).env["HTTP_REFERER"].match %r(app2)
client_id,client_secret = "",""
else
client_id,client_secret = "",""
end
env['omniauth.strategy'].options[:client_id] = client_id
env['omniauth.strategy'].options[:client_secret] = client_secret
end
https://github.com/intridea/omniauth/blob/master/lib/omniauth/strategy.rb#L292
# The setup phase looks for the `:setup` option to exist and,
# if it is, will call either the Rack endpoint supplied to the
# `:setup` option or it will call out to the setup path of the
# underlying application. This will default to `/auth/:provider/setup`.
def setup_phase
if options[:setup].respond_to?(:call)
log :info, "Setup endpoint detected, running now."
options[:setup].call(env)
elsif options.setup?
log :info, "Calling through to underlying application for setup."
setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET')
call_app!(setup_env)
end
end
补充:
SETUP_PROC = lambda do |env|
request = Rack::Request.new(env).env["HTTP_REFERER"] || Rack::Request.new(env).env["rack.session"]["omniauth.origin"]
filter = request.split("/")
client_id,client_secret = "","" if filter.include? "app1"
client_id,client_secret = "","" if filter.include? "app2"
env['omniauth.strategy'].options[:client_id] = client_id
env['omniauth.strategy'].options[:client_secret] = client_secret
end