Class: Ksef::Auth::Tokens

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

Overview

The pair returned by POST /auth/token/redeem — the contract's AuthenticationTokensResponse.

Redemption is single-use: a second call with the same authentication token returns 400 (docs/REFERENCE.md §4.2). Losing this object means repeating the whole flow, signature included, so it is worth persisting deliberately rather than incidentally.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_token ⇒ Object (readonly)

Returns the value of attribute access_token

Returns:

  • (Object) —

    the current value of access_token



11
12
13
# File 'lib/ksef/auth/tokens.rb', line 11

def access_token
  @access_token
end

#refresh_token ⇒ Object (readonly)

Returns the value of attribute refresh_token

Returns:

  • (Object) —

    the current value of refresh_token



11
12
13
# File 'lib/ksef/auth/tokens.rb', line 11

def refresh_token
  @refresh_token
end

Class Method Details

.from(payload) ⇒ Object



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

def self.from(payload)
  new(
    access_token: TokenInfo.from(payload["accessToken"]),
    refresh_token: TokenInfo.from(payload["refreshToken"])
  )
end

Instance Method Details

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

Revocation is not immediate: an access token stays valid to its exp even after permissions change (§4.2). Possession is not proof of current authorisation.

Returns:

  • (Boolean)


21
# File 'lib/ksef/auth/tokens.rb', line 21

def expired?(now = Time.now) = access_token.nil? || access_token.expired?(now)