Sha256: 26c6d2c304307939bafc782334ea87ca0393d0d9319c0ddca7ab7dc09de431f2

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module WorkOS
  # The AuthenticationResponse class represents an Authentication Response as well as an corresponding
  # response data that can later be appended on.
  class AuthenticationResponse
    include HashProvider

    attr_accessor :user, :organization_id, :impersonator, :access_token, :refresh_token

    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

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
workos-5.6.0 lib/workos/authentication_response.rb
workos-5.5.1 lib/workos/authentication_response.rb
workos-5.5.0 lib/workos/authentication_response.rb
workos-5.4.0 lib/workos/authentication_response.rb
workos-5.3.0 lib/workos/authentication_response.rb
workos-5.2.1 lib/workos/authentication_response.rb
workos-5.2.0 lib/workos/authentication_response.rb
workos-5.1.0 lib/workos/authentication_response.rb
workos-5.0.0 lib/workos/authentication_response.rb
workos-4.8.0 lib/workos/authentication_response.rb
workos-4.5.0 lib/workos/authentication_response.rb
workos-4.4.0 lib/workos/authentication_response.rb
workos-4.3.0 lib/workos/authentication_response.rb
workos-4.2.1 lib/workos/authentication_response.rb
workos-4.2.0 lib/workos/authentication_response.rb