Class: WorkOS::AuthenticationResponse

Inherits:
Object
  • Object
show all
Includes:
HashProvider
Defined in:
lib/workos/authentication_response.rb

Overview

The AuthenticationResponse class represents an Authentication Response as well as an corresponding response data that can later be appended on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashProvider

#to_h

Constructor Details

#initialize(authentication_response_json) ⇒ AuthenticationResponse

Returns a new instance of AuthenticationResponse.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/workos/authentication_response.rb', line 11

def initialize(authentication_response_json)
  json = JSON.parse(authentication_response_json, symbolize_names: true)
  @user = WorkOS::User.new(json[:user].to_json)
  @organization_id = json[:organization_id]
  @impersonator =
    if (impersonator_json = json[:impersonator])
      Impersonator.new(email: impersonator_json[:email],
                       reason: impersonator_json[:reason],)
    end
  @access_token = json[:access_token]
  @refresh_token = json[:refresh_token]
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/workos/authentication_response.rb', line 9

def access_token
  @access_token
end

#impersonatorObject

Returns the value of attribute impersonator.



9
10
11
# File 'lib/workos/authentication_response.rb', line 9

def impersonator
  @impersonator
end

#organization_idObject

Returns the value of attribute organization_id.



9
10
11
# File 'lib/workos/authentication_response.rb', line 9

def organization_id
  @organization_id
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



9
10
11
# File 'lib/workos/authentication_response.rb', line 9

def refresh_token
  @refresh_token
end

#userObject

Returns the value of attribute user.



9
10
11
# File 'lib/workos/authentication_response.rb', line 9

def user
  @user
end

Instance Method Details

#to_jsonObject



24
25
26
27
28
29
30
31
32
# File 'lib/workos/authentication_response.rb', line 24

def to_json(*)
  {
    user: user.to_json,
    organization_id: organization_id,
    impersonator: impersonator.to_json,
    access_token: access_token,
    refresh_token: refresh_token,
  }
end