Sha256: eada0e250b33bd1dd4456acd76e16288ab5c63ac56c2876c3b9b813ddfdda67a

Contents?: true

Size: 1.4 KB

Versions: 140

Compression:

Stored size: 1.4 KB

Contents

module ForestLiana
  class AuthorizationGetter
    def self.authenticate(rendering_id, auth_data)
      begin
        route = "/liana/v2/renderings/#{rendering_id.to_s}/authorization"
        headers = { 'forest-token' => auth_data[:forest_token] }

        response = ForestLiana::ForestApiRequester
          .get(route, query: {}, 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
          raise generate_authentication_error response
        end
      end
    end

    private
    def self.generate_authentication_error(error)
      case error[:message]
      when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_AND_RENDERINGID_INCONSISTENT]
        return ForestLiana::Errors::InconsistentSecretAndRenderingError.new()
      when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_NOT_FOUND]
        return ForestLiana::Errors::SecretNotFoundError.new()
      else
      end

      serverError = error[:jse_cause][:response][:body][:errors][0] || nil

      if !serverError.nil? && serverError[:name] == ForestLiana::MESSAGES[:SERVER_TRANSACTION][:names][:TWO_FACTOR_AUTHENTICATION_REQUIRED]
        return ForestLiana::Errors::TwoFactorAuthenticationRequiredError.new()
      end

      return StandardError.new(error)
    end
  end
end

Version data entries

140 entries across 140 versions & 1 rubygems

Version Path
forest_liana-7.2.1 app/services/forest_liana/authorization_getter.rb
forest_liana-7.2.0 app/services/forest_liana/authorization_getter.rb
forest_liana-7.1.0 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.2 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.1 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.6 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.5 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.4 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.3 app/services/forest_liana/authorization_getter.rb
forest_liana-6.6.2 app/services/forest_liana/authorization_getter.rb
forest_liana-6.6.1 app/services/forest_liana/authorization_getter.rb
forest_liana-6.6.0 app/services/forest_liana/authorization_getter.rb
forest_liana-6.5.1 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.2 app/services/forest_liana/authorization_getter.rb
forest_liana-6.5.0 app/services/forest_liana/authorization_getter.rb
forest_liana-6.4.1 app/services/forest_liana/authorization_getter.rb
forest_liana-7.0.0.beta.1 app/services/forest_liana/authorization_getter.rb
forest_liana-6.4.0 app/services/forest_liana/authorization_getter.rb
forest_liana-6.3.8 app/services/forest_liana/authorization_getter.rb