Class: Devise::Api::Token

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/devise/api/token.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_uniq_access_token(resource_owner) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/devise/api/token.rb', line 59

def self.generate_uniq_access_token(resource_owner)
  loop do
    token = Devise.api.config.access_token.generator.call(resource_owner)

    break token unless Devise.api.config.base_token_model.constantize.exists?(access_token: token)
  end
end

.generate_uniq_refresh_token(resource_owner) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/devise/api/token.rb', line 67

def self.generate_uniq_refresh_token(resource_owner)
  return nil unless Devise.api.config.refresh_token.enabled

  loop do
    token = Devise.api.config.refresh_token.generator.call(resource_owner)

    break token unless Devise.api.config.base_token_model.constantize.exists?(refresh_token: token)
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/devise/api/token.rb', line 39

def active?
  !inactive?
end

#expired?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/devise/api/token.rb', line 47

def expired?
  return false if Devise.api.config.access_token.expires_in_infinite.call(resource_owner)

  !!(expires_in && Time.now.utc > expires_at)
end

#inactive?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/devise/api/token.rb', line 43

def inactive?
  revoked? || expired?
end

#refresh_token_expired?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/devise/api/token.rb', line 53

def refresh_token_expired?
  return false if Devise.api.config.refresh_token.expires_in_infinite.call(resource_owner)

  Time.now.utc > refresh_token_expires_at
end

#revoked?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/devise/api/token.rb', line 35

def revoked?
  revoked_at.present?
end