Module: Devise::Models::TokenAuthenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/token_authenticatable.rb

Overview

The TokenAuthenticatable module is responsible for generating an authentication token and validating the authenticity of the same while signing in.

This module only provides a few helpers to help you manage the token. Creating and resetting the token is your responsibility.

Configuration:

You can overwrite configuration values by setting in globally in Devise (Devise.setup), using devise method, or overwriting the respective instance method.

token_authentication_key - Defines name of the authentication token params key. E.g. /users/sign_in?some_key=…

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#after_token_authenticationObject

Hook called after token authentication.



43
44
# File 'lib/devise/models/token_authenticatable.rb', line 43

def after_token_authentication
end

#ensure_authentication_tokenObject

Generate authentication token unless already exists.



33
34
35
# File 'lib/devise/models/token_authenticatable.rb', line 33

def ensure_authentication_token
  self.reset_authentication_token if self.authentication_token.blank?
end

#ensure_authentication_token!Object

Generate authentication token unless already exists and save the record.



38
39
40
# File 'lib/devise/models/token_authenticatable.rb', line 38

def ensure_authentication_token!
  self.reset_authentication_token! if self.authentication_token.blank?
end

#reset_authentication_tokenObject

Generate new authentication token (a.k.a. “single access token”).



22
23
24
# File 'lib/devise/models/token_authenticatable.rb', line 22

def reset_authentication_token
  self.authentication_token = self.class.authentication_token
end

#reset_authentication_token!Object

Generate new authentication token and save the record.



27
28
29
30
# File 'lib/devise/models/token_authenticatable.rb', line 27

def reset_authentication_token!
  reset_authentication_token
  self.save(:validate => false)
end