您需要做的是在omniauth builder中将setup设置为true
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter , :setup => true
end
然后将以下内容添加到您的 routes.rb 文件中以定义将调用哪个路由进行设置
get '/people/auth/twitter/setup' => 'sessions#twitter_setup' #needed for devise setup phase hook to work
之后只需在满足设置路由的会话控制器中设置omniauth策略
def twitter_setup
request.env['omniauth.strategy'].options[:consumer_key] = YOUR_DYNAMIC_KEY
request.env['omniauth.strategy'].options[:consumer_secret] = YOUR_DYNAMIC_SECRET_KEY
render :plain => "Setup complete.", :status => 404
end
这将使您能够加载所需的应用程序