Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to a web service with PHP given only username, password and certificate authority

I am successfully connecting, using Microsoft C#, to a Microsoft web service. I have to supply a username, password (in the C# code); and install a certificate (in .cer format) into the "Root Certificate Authorities" section of the system's certificates.

How can I connect to such a web service in PHP? The reason I ask is that all methods I have seen (such as wsdl2php, which creates a SoapClient subclass), seem to assume various things, such as SSL certificate, SSL key file and SSL key passphrase.

So it all confuses me. I'm not sure what should go where. I'm not sure where my "root certificate authority" (the .cer file) should go, and where the username and password should go. Any ideas?

like image 479
Enchilada Avatar asked Jul 26 '11 12:07

Enchilada


1 Answers

all can be done whith soapclient and stream_context_create using ssl options

<?php
$context = stream_context_create(array(
  'https' => array(
     'cafile' => '/path to file',
     'verify_peer' => true
  )));

new soapclient("https://localhost/index.php?wsdl",array(
  'login'=>'admin',
  'password'=>'passss',
  'stream_context'=> $context
));

it is not uncommon in soap to not use http auth but just an soap-call, the documnetation is essential

it can be rewarding to use soapclient whith classes using classmap to map soaptypes to php clases

like image 190
borrel Avatar answered Oct 14 '22 21:10

borrel