How can i get my PHP SoapClient to Authenticate with Digest

1.5k views Asked by At

I currently have a vb.net ASMX web service hosted on IIS along with a PHP page which is calling the web service via a SoapClient.

I need to authenticate the webservice against ActiveDirectory and i figured the easiest way to do this would be to enable Digest Authentication on IIS and allow the user to enter their AD username/password into the PHP page and send this authentication in the SoapHeaders.

I am not really quite sure how to go about this, especially when trying to contact the WSDL (which is also behind the Digest Authentication).

Any help would be appreciated.

Thanks

EDIT: What i've tried:

SERVICE_URL points to http://mypage/service.asmx?wsdl

Attempt 1: User and Pass as MD5

$options = array(
        'authentication' => SOAP_AUTHENTICATION_DIGEST,
        'realm' => 'myrealm',
        'login' => $_SESSION['authUser'],
        'password' => $_SESSION['authPass']
    );
try { $client = new SoapClient(SERVICE_URL, $options); }

Attempt 2: Auth is the 'user':'realm':'pass' as MD5:

$options = array(
        'authentication' => SOAP_AUTHENTICATION_DIGEST,
        'login' => $_SESSION['auth']
    );
try { $client = new SoapClient(SERVICE_URL, $options); }
1

There are 1 answers

1
tshimkus On

You can add headers to your soap client using SoapHeader() class/object (SoapHeader() documentation) and soap object operator __setSoapHeaders() (__setSoapHeaders() documentation).

Your request would look something like this:

<?php

    $options = array(
        'authentication' => SOAP_AUTHENTICATION_DIGEST,
        'realm' => 'myrealm',
        'login' => $_SESSION['authUser'],
        'password' => $_SESSION['authPass']
    );
    try { 
        $client = new SoapClient(SERVICE_URL, $options);

        // create and populate header array
        $headers = array();
        $headers[] = new SoapHeader('MYNAMESPACE', 
            'authentication',
            'SOAP_AUTHENTICATION_DIGEST');
        $headers[] = new SoapHeader('MYNAMESPACE', 
            'realm',
            'myrealm');

        $client->__setSoapHeaders($headers); // set headers
        $client->__soapCall("echoVoid", null); // make soap call
    }

?>