XWeb: Authenticate PHP Sample
Calling Authenticate with PHP
This is a small sample adapted from the xwebSecureClass that shows calling the Authenticate method and getting the soap headers.
Note: This code is untested. Please if edit and test the code as appropriate for your site.
$nfxweb = new SoapClient("https://mynf.mywork.org/xweb/Secure/netFORUMXML.asmx?WSDL",
Array('trace'=>true, //turning on trace=true will let us grab the headers and responses
'exceptions'=>true ));
//these are the params set in the constructor
$authReqParams = Array('userName'=>'bobbojones', 'password' => 'secretsecret');
$responseHeaders = '';
try{
//run the soap call to get it - with the headers.
$response = $nfxweb->__SoapCall("Authenticate", array('parameters'=>$authReqParams), null,null, $responseHeaders);
//Here is the auth token from our response
$authToken = $responseHeaders['AuthorizationToken']->Token;
$xwebNamespace = $response->AuthenticateResult;
} catch(SoapFault $exception) {
throw $exception;
}
//Create the header for our next request.
$authHeaders = new SoapHeader($xwebNamespace, 'AuthorizationToken', Array('Token'=>$authToken), true);
//make our next request, with the new header and capture the token again.
$arguments = Array('szObjectKey'=>"899D54C8-2D34-4E8B-B276-000B80C8958E", 'szObjectName'=>'Individual');
$response = $nfxweb->__soapCall("GetFacadeObject", $arguments, null, $authHeaders, $responseHeaders);
$authToken = $responseHeaders['AuthorizationToken']->Token;
Please note that some clients have run into some weird compatibility issues between PHP and .net web services regarding how arguments are called using SOAP calls.
Please always make sure you define the argument Array and use the argument in the SOAP call. using the sample above, you should NOT do the following:
$response = $nfxweb->__soapCall("GetFacadeObject", Array('szObjectKey'=>"899D54C8-2D34-4E8B-B276-000B80C8958E", 'szObjectName'=>'Individual'),
Code above might throw an error
Instead, do the following (define the arguments and then pass that into the SOAP call)
$arguments = Array('szObjectKey'=>"899D54C8-2D34-4E8B-B276-000B80C8958E", 'szObjectName'=>'Individual'); $response = $nfxweb->__soapCall("GetFacadeObject", $arguments, null, $authHeaders, $responseHeaders);
See Also
Avectra Web Services Integration | Jason Leveille's Blog - A detailed case study of calling the Authenticate web method and other web methods in PHP.