Class: OpenToken::Token

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/opentoken-newrelic-rails23/token.rb

Instance Method Summary collapse

Instance Method Details

#end_atObject



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

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

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  !valid?
end

#start_atObject



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

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)


12
13
14
# File 'lib/opentoken-newrelic-rails23/token.rb', line 12

def valid?
  start_at.past? && end_at.future?
end

#valid_untilObject



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

def valid_until
  payload_date('renew-until')
end

#validate!Object



8
9
10
# File 'lib/opentoken-newrelic-rails23/token.rb', line 8

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