Sha256: 8a979a22c64f9879ba380162c75642e9c74d101bef7fd2d4dfda5b11a61f860d

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

module ForestLiana
  class AuthorizationGetter
    def self.authenticate(rendering_id, use_google_authentication, auth_data, two_factor_registration)
      begin
        route = "/liana/v2/renderings/#{rendering_id.to_s}/authorization"

        if !use_google_authentication.nil?
          headers = { 'forest-token' => auth_data[:forest_token] }
        elsif !auth_data[:email].nil?
          headers = { 'email' => auth_data[:email], 'password' => auth_data[:password] }
        end

        query_parameters = {}

        unless two_factor_registration.nil?
          query_parameters['two-factor-registration'] = true
        end

        response = ForestLiana::ForestApiRequester
          .get(route, query: query_parameters, headers: headers)

        if response.code.to_i == 200
          body = JSON.parse(response.body, :symbolize_names => false)
          user = body['data']['attributes']
          user['id'] = body['data']['id']
          user
        else
          unless use_google_authentication.nil?
            raise "Cannot authorize the user using this google account. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
          else
            raise "Cannot authorize the user using this email/password. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
          end
        end
      rescue
        raise ForestLiana::Errors::HTTP401Error
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
forest_liana-6.0.0.pre.beta.4 app/services/forest_liana/authorization_getter.rb
forest_liana-6.0.0.pre.beta.3 app/services/forest_liana/authorization_getter.rb
forest_liana-6.0.0.pre.beta.2 app/services/forest_liana/authorization_getter.rb