In devise, how do i access the authentication token of a user. When an ajax call initiates a user session, I need to able to get an authentication token out of the user. I've tried to do things like adding :token_authenticable in my model
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
also adding attributes of names like :authentication_token, and :authenticity_token to attr_accessible. But every time i try to call authentication_token or this authenticity_token out of the user with user.auth ... i get errors like this
NoMethodError: undefined method `authentication_token' for #<User:0x000001016b1140>
Sorry, i need to get this token to send with my ajax calls, (the last project i worked on i had an incredibly BOOTLEG solution where devise was nearly torn out of the application, i just need this damn token)
Users of the REST API can authenticate by providing a user ID and password to the REST API login resource with the HTTP POST method. An LTPA token is generated that enables the user to authenticate future requests. This LTPA token has the prefix LtpaToken2 .
This is fixed by including the :token_authenticatable
module into the devise
user model:
devise :token_authenticatable, ...
Also the method is defined on the class itself, not an instance. Call it as User.authentication_token
.
See here: https://github.com/plataformatec/devise/blob/master/lib/devise/models/token_authenticatable.rb#L61-63.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With