Class: OpenToken::Token

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/opentoken/token.rb

Instance Method Summary collapse

Instance Method Details

#end_atObject



24
25
26
# File 'lib/opentoken/token.rb', line 24

def end_at
  payload_date('not-on-or-after')
end

#expired?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/opentoken/token.rb', line 18

def expired?
  !valid?
end

#start_atObject



21
22
23
# File 'lib/opentoken/token.rb', line 21

def start_at
  payload_date('not-before')
end

#valid?Boolean

verify that the current time is between the not-before and not-on-or-after values

Returns:

  • (Boolean)


15
16
17
# File 'lib/opentoken/token.rb', line 15

def valid?
  (start_at - CLOCK_SKEW_TOLERANCE).past? && (end_at + CLOCK_SKEW_TOLERANCE).future?
end

#valid_untilObject



27
28
29
# File 'lib/opentoken/token.rb', line 27

def valid_until
  payload_date('renew-until')
end

#validate!Object



11
12
13
# File 'lib/opentoken/token.rb', line 11

def validate!
  raise OpenToken::TokenExpiredError.new("#{Time.now.utc} is not within token duration: #{self.start_at} - #{self.end_at}") if self.expired?
end