Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to request a token when using multiple applications #100

Closed
ngw opened this issue Oct 1, 2015 · 1 comment
Closed

Unable to request a token when using multiple applications #100

ngw opened this issue Oct 1, 2015 · 1 comment

Comments

@ngw
Copy link

ngw commented Oct 1, 2015

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

My initializer (FB is the same):

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".

This is the exception raised: https://gist.github.com/ngw/1621d624a3d4ad4d683c

Callback url has been configured and is correct.

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

@ngw
Copy link
Author

ngw commented Oct 1, 2015

I found the problem, and I would definitely say it's an omniauth-twitter issue.
The problem is that

request.env['omniauth.strategy'].options[:client_id] = application.identifier
request.env['omniauth.strategy'].options[:client_secret] = application.secret

is not what the gem uses for authentication, as documented by omniauth, but

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

I fixed by setting all 4 keys in the omniauth.strategy hash, which is very dirty, very hard to spot and guess, and very hard to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant