Class: Keycardai::OAuth::TokenResponse

Inherits:
Data
  • Object
show all
Defined in:
lib/keycardai/oauth/token_types.rb

Overview

A token issued by the authorization server, the shared response shape of token exchange, client credentials, and the authorization-code exchange. scope is parsed from the space-separated wire value into an array; token_type defaults to "Bearer" when the server omits it. The complete response body is preserved in raw.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token

Returns:

  • (Object)

    the current value of access_token



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def access_token
  @access_token
end

#expires_inObject (readonly)

Returns the value of attribute expires_in

Returns:

  • (Object)

    the current value of expires_in



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def expires_in
  @expires_in
end

#id_tokenObject (readonly)

Returns the value of attribute id_token

Returns:

  • (Object)

    the current value of id_token



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def id_token
  @id_token
end

#issued_token_typeObject (readonly)

Returns the value of attribute issued_token_type

Returns:

  • (Object)

    the current value of issued_token_type



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def issued_token_type
  @issued_token_type
end

#rawObject (readonly)

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def raw
  @raw
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token

Returns:

  • (Object)

    the current value of refresh_token



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def refresh_token
  @refresh_token
end

#scopeObject (readonly)

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def scope
  @scope
end

#token_typeObject (readonly)

Returns the value of attribute token_type

Returns:

  • (Object)

    the current value of token_type



26
27
28
# File 'lib/keycardai/oauth/token_types.rb', line 26

def token_type
  @token_type
end

Class Method Details

.from_wire(payload) ⇒ TokenResponse

Parameters:

  • payload (Hash)

    the parsed token-endpoint response body

Returns:

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/keycardai/oauth/token_types.rb', line 32

def self.from_wire(payload)
  access_token = payload["access_token"]
  unless access_token.is_a?(String) && !access_token.empty?
    raise ProtocolError.new("token response has no access_token", code: "invalid_response")
  end

  new(
    access_token: access_token,
    token_type: payload["token_type"] || "Bearer",
    expires_in: payload["expires_in"],
    scope: payload["scope"]&.split,
    issued_token_type: payload["issued_token_type"],
    refresh_token: payload["refresh_token"],
    id_token: payload["id_token"],
    raw: payload
  )
end