我已经在omniauth wiki上配置了devise + omniauth:https://github.com/intridea/omniauth/wiki/Setup-Phase
我的初始化程序:
provider :twitter, nil, nil, setup: true
routes.rb中:
get '/settings/auth/:provider/setup' => 'settings/authorization_callbacks#setup'
这是设置操作
def setup
application_id = params[:application_id].present? ? params[:application_id] : request.env["rack.session"]["omniauth.params"]["application_id"]
application = Application.find(application_id)
request.env['omniauth.strategy'].options[:client_id] = application.identifier
request.env['omniauth.strategy'].options[:client_secret] = application.secret
render :text => "Setup complete.", :status => 404
end
结果是400 Bad Request,我不明白为什么...... 我检查了正确的应用程序,在“omniauth.strategy”中设置了正确的值。
也许有人已经实现了这个可以猜出我的代码有什么问题?提前谢谢。
答案 0 :(得分:0)
这是omniauth-twitter gem中的一个错误。
为Twitter设置的关键是
request.env['omniauth.strategy'].options[:consumer_key] = application.identifier
request.env['omniauth.strategy'].options[:consumer_secret] = application.secret