I am creating an ember app that has devise worked in for authentication. I'm really getting stuck with how all these different tokens come into play.
I'm reimplementing the recently deprecated :token_authenticatable
devise "strategy" using the method described here. I'd like to add token authentication to my API and sign requests to that with the user's token.
What I'm wondering is, even though it's using Devise.secure_compare
to thwart timing attacks, it's still storing the authentication_token
in plain text, so if anyone were to gain access to the database, those tokens could potentially used to steal a session, no?
Devise seems to use two different types of "tokens" in the modules:
- Creating a token with
Devise.friendly_token
and storing it as plain text. Then doing a look up by this token (as used in:rememberable
). - Creating a salted token with
Devise.token_generator
(as seem in:confirmable
).
The second method looks to me like the token is salted using Devise.secret_key
which is derived from the Rails secret in config/secrets.yml. That way the token is encrypted and if the database was exposed for some reason, the tokens couldn't be used, right? Would be the equivalent of having a private key (rails secret) and a public key (authentication_token).
I have quite a few concerns:
- Should I use Devise.token_generator to create my
authentication_token
s? - What is the word on security for these type of tokens?
- How does the CSRF token factor into Devise?