Class: Devise::Api::Token
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Devise::Api::Token
- Defined in:
- lib/devise/api/token.rb
Class Method Summary collapse
- .generate_uniq_access_token(resource_owner) ⇒ Object
- .generate_uniq_refresh_token(resource_owner) ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #expired? ⇒ Boolean
- #inactive? ⇒ Boolean
- #refresh_token_expired? ⇒ Boolean
- #revoke! ⇒ Object
-
#revoke_family! ⇒ Object
Revokes every token in this token's refresh chain (ancestors and descendants).
- #revoked? ⇒ Boolean
Class Method Details
.generate_uniq_access_token(resource_owner) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/devise/api/token.rb', line 78 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
86 87 88 89 90 91 92 93 94 |
# File 'lib/devise/api/token.rb', line 86 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
58 59 60 |
# File 'lib/devise/api/token.rb', line 58 def active? !inactive? end |
#expired? ⇒ Boolean
66 67 68 69 70 |
# File 'lib/devise/api/token.rb', line 66 def expired? return false if Devise.api.config.access_token.expires_in_infinite.call(resource_owner) !!(expires_in && Time.current > expires_at) end |
#inactive? ⇒ Boolean
62 63 64 |
# File 'lib/devise/api/token.rb', line 62 def inactive? revoked? || expired? end |
#refresh_token_expired? ⇒ Boolean
72 73 74 75 76 |
# File 'lib/devise/api/token.rb', line 72 def refresh_token_expired? return false if Devise.api.config.refresh_token.expires_in_infinite.call(resource_owner) Time.current > refresh_token_expires_at end |
#revoke! ⇒ Object
43 44 45 46 47 48 |
# File 'lib/devise/api/token.rb', line 43 def revoke! return self if revoked? update!(revoked_at: Time.current) self end |
#revoke_family! ⇒ Object
Revokes every token in this token's refresh chain (ancestors and descendants). Used for refresh-token reuse detection when refresh_token.rotation_enabled is on.
52 53 54 55 56 |
# File 'lib/devise/api/token.rb', line 52 def revoke_family! transaction do family_tokens.each(&:revoke!) end end |
#revoked? ⇒ Boolean
39 40 41 |
# File 'lib/devise/api/token.rb', line 39 def revoked? revoked_at.present? end |