Basic Auth to authenticate webservice Soap - PHP

Asked

Viewed 1,432 times

1

I am having a problem with authentication when I try to consume a web service Soap. When entering the url in the browser, a dailog is shown asking for user and password. However, I need to do this authentication without this dialog being presented, that is, all the authentication in the back end. I tried to pass the login and password through Soapheader but without success. Follows the script:

!IMPORTANT: O tipo de autenticação é (Basic auth)    

$credenciais = self::fncGeraAuth();   
//array que contem user e senha para autenticação    
//Array ( [UserName] => xxxxx [Password] => xxxxx) 

$_rCliente2 = new SoapClient($wsdl, array("encoding" => "ISO-8859-1"));  

$Header = new SoapHeader($wsdl,'Authorization', $credenciais, false);

$_rCliente2->__setSoapHeaders($Header);

$result = $_rCliente2->fncRecuperaPapel($Instituição);
//tentado acessar uma função do webservice passando um parametro 

var_dump($result);
exit();

Erro:
SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from '
...........?wsdl' : failed to load external entity ".........wsdl" 

1 answer

0


Good afternoon!

I did a quick test locally, with a service wsdl done in PHP, using Basic Auth HTTP.

I was able to authenticate by logging in and password directly to Soapclient.

$client = new SoapClient('http://teste-soap.local/server.php?wsdl',['trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE, 'login' => 'adriano', 'password' => 'maciel']);

I also tried to use the Soapheader, but this does not work in this case, because the authentication must be done by instantiating the client.

  • I’m still having the same error...the 'login' and 'password' item is standard for Basic Auth or you can set this to another name?

  • You can pass any key and value, in case I wait on the server the default authentication. Mount using: $_SERVER['PHP_AUTH_USER']; and $_SERVER['PHP_AUTH_PW']; The fields you will pass, depend on the server you are authenticating.

  • see how I rode $_rCliente2 = new Soapclient($_uWS, array ("encoding" => "UTF-8", "cache_wsdl"=>WSDL_CACHE_NONE, "Username" => $credentials[Username], "Password" => $credentials[Username])); in my case the web service was written in java although I believe this does not interfere.

  • Thank you Adriano...your answer worked for my problem! happens that for Basic Auth you must use "login" for the username and "password" for the password, following this pattern the authentication will successfully follow ! Thank you and success for you !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.