简体   繁体   中英

Multiple Twitter applications with omniauth

I've configured devise + omniauth as documented on omniauth wiki: https://github.com/intridea/omniauth/wiki/Setup-Phase

My initializer:

provider :twitter, nil, nil, setup: true

routes.rb:

get '/settings/auth/:provider/setup' => 'settings/authorization_callbacks#setup'

This is the setup action

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

Result is 400 Bad Request and I have no idea why... I checked and the right application is called, setting the right values in the "omniauth.strategy".

Maybe someone who already implemented this can guess what's the problem with my code? Thanks in advance.

This was a bug in omniauth-twitter gem.

The keys to set for Twitter are

request.env['omniauth.strategy'].options[:consumer_key] = application.identifier
request.env['omniauth.strategy'].options[:consumer_secret] = application.secret

https://github.com/arunagw/omniauth-twitter/issues/100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM