Class: Ksef::Auth::TokenInfo

Inherits:
Data
  • Object
show all
Defined in:
lib/ksef/auth/token_info.rb,
lib/ksef/auth/token_info.rb

Overview

Reopened rather than using a Data.define block so REDACTED lands on the class.

Constant Summary collapse

REDACTED =
"[REDACTED]"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#token ⇒ Object (readonly)

Returns the value of attribute token

Returns:

  • (Object) —

    the current value of token



6
7
8
# File 'lib/ksef/auth/token_info.rb', line 6

def token
  @token
end

#valid_until ⇒ Object (readonly)

Returns the value of attribute valid_until

Returns:

  • (Object) —

    the current value of valid_until



6
7
8
# File 'lib/ksef/auth/token_info.rb', line 6

def valid_until
  @valid_until
end

Class Method Details

.from(payload) ⇒ Object



12
13
14
15
16
# File 'lib/ksef/auth/token_info.rb', line 12

def self.from(payload)
  return nil if payload.nil?

  new(token: payload["token"], valid_until: Ksef::Auth.time(payload["validUntil"]))
end

Instance Method Details

#expired?(now = Time.now) ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'lib/ksef/auth/token_info.rb', line 18

def expired?(now = Time.now) = !valid_until.nil? && valid_until <= now

#inspect ⇒ Object



24
# File 'lib/ksef/auth/token_info.rb', line 24

def inspect = "#<data Ksef::Auth::TokenInfo token=#{REDACTED} valid_until=#{valid_until.inspect}>"

#to_s ⇒ Object

Both redacted, and #to_s deliberately so: these are bearer credentials, and returning the raw JWT here would make "...#{token_info}" in any log line leak a live one (DESIGN.md §4.5). Reaching for the value is an explicit #token call.



23
# File 'lib/ksef/auth/token_info.rb', line 23

def to_s = REDACTED