Php gets SOAP header Username and password from SOAP SERVER

I need to create a PHP, SOAP API. I need to authenticate a SOAP client from a SOAP server. This is the SOAP client code.

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

I need to commit and verify this username and password from the server (SOAP SERVER). This is my SOAP server code

 class getDb { //return DATA } $server = new SoapServer("cust.wsdl"); $server->setClass("getDb"); $server->handle(); 

I need to check the username and password of the user on the SOAP server.

Does anyone know how to capture the SOAP username and password ("user" => "username", "pass" => "password") from SOAPSERVER, please provide.

+4
source share
4 answers

I used the method below and received a successful PHP SOAP authentication response from the HTTP Auth method.

My client SOAP statement looks like

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

I used this PHP statement for the 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 } 
+1
source

Auth data can be written as follows.

  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'); echo 'Auth failed'; exit; } 

Any output can be generated for header('HTTP/1.0 401 Unauthorized');

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

The 2 items above are usually the username and password of the user. If you need to verify them, you can do this at a basic apache authorization level. If you need to do this at the php level, you will need to write a session handler based on the HTTP protocol, which requires security to show resources. An example of this is here: http://php.net/manual/en/features.http-auth.php Most developers simply use a basic auth apache tied to LDAP or some other service to process the auth request and have a soap service to deal with actual work.

+2
source

You can use php input stream to receive raw xml que request and then extract part of header.

0
source

All Articles