0

I am trying to authenticate a site. I found an example for PHP, but I'm having some trouble rewriting it to Ruby.

Example code:

class HRDConfig {
    public $uid = "myuid";
    public $pass = "mypassword123"; 

    const NS = "https://www.tested.site.com/partnerAPI/";
    const PARTNER = "https://www.tested.site.com/partnerAPI/Partner.php?wsdl";
}

ini_set("soap.wsdl_cache_enabled", "1"); 
$soap = new SoapClient(HRDConfig::PARTNER, array("encoding"=>"UTF-8", "exceptions" => true));
$soap->__setSoapHeaders(array(new SoapHeader(HRDConfig::NS, "AuthHeader", new HRDConfig())));

My code:

client = Savon.client(
    wsdl: 'https://www.tested.site.com/partnerAPI/Partner.php?wsdl',
    soap_header:{
            'AuthHeader' => {'uid'=>'myuid','pass'=>'mypass'}
    })

What I'm doing wrong?

Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
dobrunya
  • 1
  • 1
  • possible duplicate of [How to write SOAP Authentication header with Ruby Savon](http://stackoverflow.com/questions/19284392/how-to-write-soap-authentication-header-with-ruby-savon) – Brad Werth Mar 15 '15 at 01:20

1 Answers1

0
$client = new SoapClient(
                  'http://service.example.com?wsdl',
                  array('soap_version'    => '1.2',
                        'connect_timeout' => 10,
                        'compression'     => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
                        'cache_wdsl'      => WSDL_CACHE_NONE));

$header = new SoapHeader(
                  'http://service.example.com?wsdl',
                  'AuthenticateRequest',
                  new SoapVar(array('apiKey' => '***api******'), SOAP_ENC_OBJECT),
                  true);

$client->__setSoapHeaders($header);

try {
    echo("\n[SOAP response]\n");
    $response = $client->__soapCall('your function', array());
    echo("\n[After response]\n");
    echo("\n{$response }\n");
}
catch (Exception $e) {
    echo($e->getMessage());
}

Note: here "apiKey" is my params to authenticate api, your can be different

Mukesh
  • 921
  • 10
  • 23