Skip to main content
Notice removed Reward existing answer by Aaron Gray
Bounty Ended with Ashitaka's answer chosen by Aaron Gray
Notice added Reward existing answer by Aaron Gray
Bounty Started worth 50 reputation by Aaron Gray
edited tags
Link
Volodymyr B.
  • 3.4k
  • 2
  • 33
  • 50
Notice removed Canonical answer required by Jeff Escalante
Bounty Ended with Ashitaka's answer chosen by Jeff Escalante
Notice added Canonical answer required by Jeff Escalante
Bounty Started worth 50 reputation by Jeff Escalante
Source Link
Jeff Escalante
  • 3.2k
  • 1
  • 24
  • 30

Is devise's token_authenticatable secure?

I'm building a simple api with Rails API, and want to make sure I'm on the right track here. I'm using devise to handle logins, and decided to go with Devise's token_authenticatable option, which generates an API key that you need to send with each request.

I'm pairing the API with a backbone/marionette front end and am generally wondering how I should handle sessions. My first thought was to just store the api key in local storage or a cookie, and retrieve it on page load, but something about storing the api key that way bothered me from a security standpoint. Wouldn't be be easy to grab the api key either by looking in local storage/the cookie or sniffing any request that goes through, and use it to impersonate that user indefinitely? I currently am resetting the api key each login, but even that seems frequent - any time you log in on any device, that means you'd be logged out on every other one, which is kind of a pain. If I could drop this reset I feel like it would improve from a usability standpoint.

I may be totally wrong here (and hope I am), can anyone explain whether authenticating this way is reliably secure, and if not what a good alternative would be? Overall, I'm looking for a way I can securely keep users 'signed in' to API access without frequently forcing re-auth.