Search code examples
phpsoapsoap-clientnusoap

php get SOAP header Username and Password from SOAP SERVER


I have to create PHP, SOAP API. I need to authenticate SOAP client from SOAP Server. This is the code of SOAP Client.

 $client = new SoapClient("cust.wsdl",array(
"trace"      => 1,
"exceptions" => 0,
"user" => 'username',
"pass" => 'password'));

$result = $client->getDetails($value1);

I need to capture and validate these username and password from server (SOAP SERVER) side. This is my SOAP Server Code

class getDb {
//return DATA 
}

$server = new SoapServer("cust.wsdl");
$server->setClass("getDb");
$server->handle();

I need to Validate Client's Username and Password from SOAP Server.

Anyone know how to capture SOAP Username and Password ("user" => 'username', "pass" => 'password') from SOAPSERVER please provide.


Solution

  • I have used below method and got success SOAP PHP authentication response from HTTP Auth method.

    My SOAP client statement as look like

    $client = new SoapClient("name.wsdl",array(
    "trace"      => 1,
    "exceptions" => 0,
    "login" => 'xxx',
    "password" => 'xxx'));
    

    I used this PHP statement for Authenticate PHP Auth header

        if(($_SERVER['PHP_AUTH_PW']!= $pass
     || $_SERVER['PHP_AUTH_USER'] != $login)
     || !$_SERVER['PHP_AUTH_USER'])
        {
            header('WWW-Authenticate: Basic realm="Test auth"');
            header('HTTP/1.0 401 Unauthorized');
            // OR ANY THING
    }