PHP nusoap webservice security

geetha picture geetha · Nov 8, 2010 · Viewed 15.4k times · Source

I am writing soap server and soap client in php. For Authentication of soap services , i want to use "usernametoken" for security. Can anyone send me the example applied in server and client using nusoap.

I am using nusoap to write the soap services.

Thanks & Regards, neetha

Answer

Abhishek Saha picture Abhishek Saha · Feb 21, 2011

SERVER Side:

function doAuthenticate(){    
if(isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) )
          {
           //here I am hardcoding. You can connect to your DB for user authentication.    

           if($_SERVER['PHP_AUTH_USER']=="abhishek" and $_SERVER['PHP_AUTH_PW']="123456" )
                return true;
           else
               return  false;                   

           }
}

Call this doAuthenticate function for every operation in server.If it is returning true then only allow the client/user to communicate.

CLIENT side

// includes nusoap class
require_once('../lib/nusoap.php');

// Create object
$client = new nusoap_client('<wsdl path>?wsdl', true);
//Setting credentials for Authentication 
$client->setCredentials("abhishek","123456","basic");
..