def refresh_token
      debug { "Performing token refresh" }
      return false if token.nil?
      return false if token['refresh_token'].nil?
      uri = URI.parse(token_account['token_endpoint'])
      endpoint_data = { path: uri.path }
      endpoint_data[:host] = uri.host if uri.host
      endpoint_data[:port] = uri.port if uri.port

      debug { "Token refresh endpoint: #{endpoint_data.inspect}" }

      return false unless endpoint_data[:path]

      response = request(
        {
          http_method: token_account['token_method'].downcase.to_sym,
          body: refresh_request_params,
          headers: {
            CONTENT_TYPE => token_account['token_post_content_type']
          }.merge(
            token_account['code_requires_basic_auth'] ? basic_auth_header : {}
          ),
          expects: [200, 201, 400, 401, 403],
          auth: false
        }.merge(endpoint_data)
      )

      if response && response['access_token']
        debug { "Got response to refresh request" }
        token['access_token']  = response['access_token']
        token['refresh_token'] = response['refresh_token']
        token['expires_at'] = in_to_at(response['expires_in'])
        token.config.write if token.respond_to?(:config)
        true
      else
        debug { "Got null or bad response to refresh request: #{last_response.inspect}" }
        false
      end
    rescue => ex
      error { "Access token refresh exception" }
      error { ex }
      false
    end
def refresh_token
      debug { "Performing token refresh" }
      return false if token.nil?
      return false if token['refresh_token'].nil?
      uri = URI.parse(token_account['token_endpoint'])
      endpoint_data = { path: uri.path }
      endpoint_data[:host] = uri.host if uri.host
      endpoint_data[:port] = uri.port if uri.port

      debug { "Token refresh endpoint: #{endpoint_data.inspect}" }

      return false unless endpoint_data[:path]

      response = request(
        {
          http_method: token_account['token_method'].downcase.to_sym,
          body: refresh_request_params,
          headers: {
            CONTENT_TYPE => token_account['token_post_content_type']
          }.merge(
            token_account['code_requires_basic_auth'] ? basic_auth_header : {}
          ),
          expects: [200, 201, 400, 401, 403],
          auth: false
        }.merge(endpoint_data)
      )

      if response && response['access_token']
        debug { "Got response to refresh request" }
        token['access_token']  = response['access_token']
        token['refresh_token'] = response['refresh_token']
        token['expires_at'] = in_to_at(response['expires_in'])
        token.config.write if token.respond_to?(:config)
        true
      else
        debug { "Got null or bad response to refresh request: #{last_response.inspect}" }
        false
      end
    rescue => ex
      error { "Access token refresh exception" }
      error { ex }
      false
    end
Perform refresh token request to auth provider.
 Updates the client's Token object and writes changes to
 configuration.

 @param [Boolean] use_basic_auth? When true, use basic auth authentication header
 @return [Boolean] success?