simple_token_authentication icon indicating copy to clipboard operation
simple_token_authentication copied to clipboard

Use "Authorization" to pass the token

Open Juanadelacuesta opened this issue 7 years ago • 2 comments

Hello! I'm currently implementing an app with Devise and Simple Token Authentication, but the consumer of my app doesn't want to use custom headers, is it possible to use the mentioned header and to prepend the token with "Token" in order to comply with HTTP simple auth?

Thank you!

Juanadelacuesta avatar Sep 04 '17 22:09 Juanadelacuesta

Yeah, this is exactly what ember-simple-auth expects to do with the Devise authorizer, presumably because that's the format Devise expected when using token authentication.

ClayShentrup avatar Nov 26 '17 02:11 ClayShentrup

Hi @Juanadelacuesta,

For the first part - customizing the header name - you can use the header_names option (docs)

# config/initializers/simple_token_authentication.rb

SimpleTokenAuthentication.configure do |config|
  # Configure the name of the HTTP headers watched for authentication (assuming user is the resource).
  config.header_names = { user: { authentication_token: 'Authorization' } }
end

However, if what you want to obtain is the following (thank you @ClayShentrup for the reference): Authorization: token="234rtgjneroigne4" email="[email protected]", that won't be enough.

The gem currently doesn't support reading both the token and the identifier (typically email) from the same header. The relevant parts of the code are:

Does that answer you question?

Note that this aspect of Simple Token Authentication could be made more flexible with some effort, and I'm not against working towards that if it is useful. Meaning: I'm happy to contribute on a PR, but I would not start that on myself : )

Last but not least, if you find or write an alternative that suits your needs, please add it to this page of the Devise wiki - I've added Tiddle recently, and I think it's a great thing that the page exists.

gonzalo-bulnes avatar Nov 26 '17 10:11 gonzalo-bulnes