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

Authenticating to Rails API using authenticate_or_request_with_http_token #47

Closed
natebird opened this issue Nov 8, 2012 · 2 comments
Closed

Comments

@natebird
Copy link

natebird commented Nov 8, 2012

The sample code in the readme

def call(env)
  env[:request_headers]["X-API-Token"] = @options[:token] if @options.include?(:token)
  @app.call(env)
end

produces the following header: "X-API-TOKEN"=>"bb2b2dd75413d3"

Using the built-in Rails token authentication method (authenticate_or_request_with_http_token) it needs to come in like this: "HTTP_AUTHORIZATION"=>"Token token=\"bb2b2dd75413d3\"".

Am I missing anything or how can I change the sent header?

@remi
Copy link
Owner

remi commented Nov 8, 2012

It’s just some non-Rails specific sample code :) The X-API-Token is an arbitrary value. If you want to send the specified header, you can use this:

def call(env)
  env[:request_headers]["HTTP_AUTHORIZATION"] = "Token: token=\"#{@options[:token]}\"" if @options.include?(:token)
  @app.call(env)
end

It should work!

@natebird
Copy link
Author

natebird commented Nov 8, 2012

Ahh. Of course it is that easy. Thanks for the quick response.

@natebird natebird closed this as completed Nov 8, 2012
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

2 participants