How to pass through credentials to PHP SOAP Request

783

I need to create a PHP SOAP client based on this specification:

https://exdev.server.propctrl.com/v5.4/Basic/AgencyIntegration.svc?wsdl

I am able to create my soap client, and when I try to call a function it returns saying access denied:

Message: Access is denied.

Based on documentation, there is no verification/auth method that I first need to call, but it seems I have to use a type called Credentials.

struct Credentials { string Password; string Username; }

I then tried created a Credentials object:

class Credentials {
  public function __construct($username, $password) 
  {
      $this->username = $username;
      $this->password = $password;
  }
}

And assigned new values to it and used it in my SoapHeaders:

$credentials = new Credentials($username, $password);
$header = new SoapHeader('http://localhost','Credentials',$credentials,false);
$client->__setSoapHeaders($header);

When I then use a function I still get the same error:

echo "<pre>";
try {
$response = $client->__soapCall("EchoAuthenticated", array("EchoAuthenticated" => "asdfasdf"));
var_dump($response);
}
//catch exception
catch(Exception $e) {
  echo 'Message: ' .$e->getMessage();
}

Message: Access is denied.

I guess my question is that I don't know where/how to pass through the credentials in order for the API to authorise my request.

Any ideas/suggestions?

update1:

enter image description here

390

Answer

Solution:

The authentication method should be explained in some documentation, anyway there are Soap services that use HTTP Header for authentication, for example

            $soapClient->setHttpHeaders([
                'clientId' => $username,
                'clientSecret' => $password
            ]); 

But please consider that keys ( in my example clientId and clientSecret ) depend by the service implementation. Do you have a service documentation?

People are also looking for solutions to the problem: php - Parsing ? in htaccess

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.