def get_authorized
      retries = redirects = 0
      api_url = @api_url
      begin
        Log.info("Getting authorized via #{@api_url}")
        params = {
          :grant_type => "client_credentials",
          :account_id => @account_id,
          :r_s_version => AgentConfig.protocol_version,
          :right_link_version => RightLink.version }
        response = @http_client.post("/oauth2", params,
          :headers => @other_headers,
          :open_timeout => DEFAULT_OPEN_TIMEOUT,
          :request_timeout => DEFAULT_REQUEST_TIMEOUT)
        response = SerializationHelper.symbolize_keys(response)
        @access_token = response[:access_token]
        @expires_at = Time.now + response[:expires_in]
        update_urls(response)
        self.state = :authorized
        @communicated_callbacks.each { |callback| callback.call } if @communicated_callbacks
      rescue BalancedHttpClient::NotResponding
        if (retries += 1) > MAX_RETRIES
          ErrorTracker.log(self, "Exceeded maximum authorization retries (#{MAX_RETRIES})")
        else
          sleep(RETRY_INTERVAL)
          retry
        end
        raise
      rescue HttpExceptions::MovedPermanently, HttpExceptions::Found => e
        if (redirects += 1) > MAX_REDIRECTS
          ErrorTracker.log(self, "Exceeded maximum redirects (#{MAX_REDIRECTS})")
        elsif redirected(e)
          retry
        end
        @api_url = api_url
        raise
      rescue HttpExceptions::Unauthorized => e
        self.state = :unauthorized
        @access_token = nil
        @expires_at = Time.now
        raise Exceptions::Unauthorized.new(e.http_body, e)
      end
      true
    rescue BalancedHttpClient::NotResponding, Exceptions::Unauthorized, CommunicationModeSwitch, Exceptions::ConnectivityFailure
      raise
    rescue StandardError => e
      ErrorTracker.log(self, "Failed authorizing", e)
      self.state = :failed
      raise
    end
def get_authorized
      retries = redirects = 0
      api_url = @api_url
      begin
        Log.info("Getting authorized via #{@api_url}")
        params = {
          :grant_type => "client_credentials",
          :account_id => @account_id,
          :r_s_version => AgentConfig.protocol_version,
          :right_link_version => RightLink.version }
        response = @http_client.post("/oauth2", params,
          :headers => @other_headers,
          :open_timeout => DEFAULT_OPEN_TIMEOUT,
          :request_timeout => DEFAULT_REQUEST_TIMEOUT)
        response = SerializationHelper.symbolize_keys(response)
        @access_token = response[:access_token]
        @expires_at = Time.now + response[:expires_in]
        update_urls(response)
        self.state = :authorized
        @communicated_callbacks.each { |callback| callback.call } if @communicated_callbacks
      rescue BalancedHttpClient::NotResponding
        if (retries += 1) > MAX_RETRIES
          ErrorTracker.log(self, "Exceeded maximum authorization retries (#{MAX_RETRIES})")
        else
          sleep(RETRY_INTERVAL)
          retry
        end
        raise
      rescue HttpExceptions::MovedPermanently, HttpExceptions::Found => e
        if (redirects += 1) > MAX_REDIRECTS
          ErrorTracker.log(self, "Exceeded maximum redirects (#{MAX_REDIRECTS})")
        elsif redirected(e)
          retry
        end
        @api_url = api_url
        raise
      rescue HttpExceptions::Unauthorized => e
        self.state = :unauthorized
        @access_token = nil
        @expires_at = Time.now
        raise Exceptions::Unauthorized.new(e.http_body, e)
      end
      true
    rescue BalancedHttpClient::NotResponding, Exceptions::Unauthorized, CommunicationModeSwitch, Exceptions::ConnectivityFailure
      raise
    rescue StandardError => e
      ErrorTracker.log(self, "Failed authorizing", e)
      self.state = :failed
      raise
    end
def get_authorized retries = redirects = 0 api_url = @api_url begin Log . info ( "Getting authorized via #{@api_url}" ) params = { :grant_type => "client_credentials" , :account_id => @account_id , :r_s_version => AgentConfig . protocol_version , :right_link_version => RightLink . version } response = @http_client . post ( "/oauth2" , params , :headers => @other_headers , :open_timeout => DEFAULT_OPEN_TIMEOUT , :request_timeout => DEFAULT_REQUEST_TIMEOUT ) response = SerializationHelper . symbolize_keys ( response ) @access_token = response [ :access_token ] @expires_at = Time . now + response [ :expires_in ] update_urls ( response ) self . state = :authorized @communicated_callbacks . each { | callback | callback . call } if @communicated_callbacks rescue BalancedHttpClient :: NotResponding if ( retries += 1 ) > MAX_RETRIES ErrorTracker . log ( self , "Exceeded maximum authorization retries (#{MAX_RETRIES})" ) else sleep ( RETRY_INTERVAL ) retry end raise rescue HttpExceptions :: MovedPermanently , HttpExceptions :: Found => e if ( redirects += 1 ) > MAX_REDIRECTS ErrorTracker . log ( self , "Exceeded maximum redirects (#{MAX_REDIRECTS})" ) elsif redirected ( e ) retry end @api_url = api_url raise rescue HttpExceptions :: Unauthorized => e self . state = :unauthorized @access_token = nil @expires_at = Time . now raise Exceptions :: Unauthorized . new ( e . http_body , e ) end true rescue BalancedHttpClient :: NotResponding , Exceptions :: Unauthorized , CommunicationModeSwitch , Exceptions :: ConnectivityFailure raise rescue StandardError => e ErrorTracker . log ( self , "Failed authorizing" , e ) self . state = :failed raise end
Get authorized with RightApi using OAuth2
 As an extension to OAuth2 receive URLs needed for other servers
 Retry authorization if RightApi not responding or if get redirected

 @return [TrueClass] always true

 @raise [Exceptions::Unauthorized] authorization failed
 @raise [BalancedHttpClient::NotResponding] cannot access RightApi
 @raise [CommunicationModeSwitch] changing communication mode
Get authorized with RightApi using OAuth2 As an extension to OAuth2 receive URLs needed for other servers Retry authorization if RightApi not responding or if get redirected