Class: Wor::Authentication::DecodedToken
- Inherits:
-
Object
- Object
- Wor::Authentication::DecodedToken
- Defined in:
- lib/wor/authentication/decoded_token.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #able_to_renew? ⇒ Boolean
- #expired? ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize(payload) ⇒ DecodedToken
constructor
A new instance of DecodedToken.
- #valid_renew_id?(renew_id) ⇒ Boolean
- #validate!(entity_custom_validation = nil) ⇒ Object
Constructor Details
#initialize(payload) ⇒ DecodedToken
Returns a new instance of DecodedToken.
6 7 8 |
# File 'lib/wor/authentication/decoded_token.rb', line 6 def initialize(payload) @payload = payload end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
4 5 6 |
# File 'lib/wor/authentication/decoded_token.rb', line 4 def payload @payload end |
Instance Method Details
#able_to_renew? ⇒ Boolean
27 28 29 30 |
# File 'lib/wor/authentication/decoded_token.rb', line 27 def able_to_renew? # TODO: Use a ruby standard library for time fetch(:maximum_useful_date).present? && Time.zone.now.to_i < fetch(:maximum_useful_date) end |
#expired? ⇒ Boolean
22 23 24 25 |
# File 'lib/wor/authentication/decoded_token.rb', line 22 def expired? # TODO: Use a ruby standard library for time fetch(:expiration_date).present? && Time.zone.now.to_i > fetch(:expiration_date) end |
#fetch(key) ⇒ Object
18 19 20 |
# File 'lib/wor/authentication/decoded_token.rb', line 18 def fetch(key) payload[key.to_sym] || payload[key.to_s] end |
#valid_renew_id?(renew_id) ⇒ Boolean
32 33 34 |
# File 'lib/wor/authentication/decoded_token.rb', line 32 def valid_renew_id?(renew_id) (fetch(:renew_id).blank? || renew_id.blank?) || renew_id == fetch(:renew_id) end |
#validate!(entity_custom_validation = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/wor/authentication/decoded_token.rb', line 10 def validate!(entity_custom_validation = nil) unless valid_entity_custom_validation?(entity_custom_validation) raise Wor::Authentication::Exceptions::EntityCustomValidationError end raise Wor::Authentication::Exceptions::NotRenewableTokenError unless able_to_renew? raise Wor::Authentication::Exceptions::ExpiredTokenError if expired? end |