Recipe 14.8. Using Authentication with SOAP

14.8.1. Problem

You need to authenticate your SOAP requests using HTTP Basic Authentication.

14.8.2. Solution

Pass a username and password in via the options array by setting the login and password keys:

$options = array('login' => 'elvis',                  'password' => 'the-king'); $client = new SOAPClient('',                          $options);

14.8.3. Discussion

There are a number of ways to handle authentication within SOAP requests. A few popular ways are HTTP Basic Authentication, placing data inside the SOAP header, and using the WS-* specifications, including WS-Security.

To make ext/soap add HTTP Basic Authentication credentials to every request, pass your username and password in as options when you create the SOAP client:

<?php $options = array('login' => 'elvis',                  'password' => 'the-king'); $client = new SOAPClient('',                          $options); ?>

Now every request will have an additional HTTP header of Authorization.

If your service requires data set in the SOAP request header, see Recipe 26.1 for details on handling that.

As of this writing, you cannot use any XML Security specifications with ext/soap. However, Rob Richards is working on it. For more information, check out

14.8.4. See Also

Recipe 15.8 for handling SOAP authentication in a SOAP server.

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: