Class: ForestLiana::TwoFactorRegistrationConfirmer

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/two_factor_registration_confirmer.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_id, use_google_authentication, auth_data) ⇒ TwoFactorRegistrationConfirmer

Returns a new instance of TwoFactorRegistrationConfirmer.



3
4
5
6
7
8
9
10
11
# File 'app/services/forest_liana/two_factor_registration_confirmer.rb', line 3

def initialize(
  project_id,
  use_google_authentication,
  auth_data
)
  @project_id = project_id
  @use_google_authentication = use_google_authentication
  @auth_data = auth_data
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/forest_liana/two_factor_registration_confirmer.rb', line 13

def perform
  begin
    body_data = { 'useGoogleAuthentication' => @use_google_authentication }

    if @use_google_authentication
      body_data['forestToken'] = @auth_data[:forest_token]
    else
      body_data['email'] = @auth_data[:email]
    end

    response = ForestLiana::ForestApiRequester.post(
      "/liana/v2/projects/#{@project_id}/two-factor-registration-confirm",
      body: body_data,
    )

    unless response.is_a?(Net::HTTPOK)
      raise "Cannot retrieve the data from the Forest server. Forest API returned an #{ForestLiana::Errors::HTTPErrorHelper.format(response)}"
    end
  rescue
    raise ForestLiana::Errors::HTTP401Error
  end
end