Search code examples
phpnusoap

What is a good way to pass authentication info to API methods in PHP NuSoap?


I am using NuSoap to implement an api server. The public SOAP API may have a method such as:

function createComment(articleID, content);

This would ideally create a comment on the given article and attribute it to the user who was authenticated.

Authentication is being handled via http auth. So, the nusoap_server object has the user information.

How can createComment have access this information? It knows nothing about the server. I wanted to avoid putting the user info in the global space, but I am starting to think there's no other easy way.

Is there a technique that allows the public signature for the method to remain as stated above, while the implementation method has additional arguments (user info)?


Solution

  • SoapServer is meant to provide a means to call a function w/ parameters remotely. The function being called doesn't have any information about the SoapServer handling the communication to make this happen--all it sees is the parameter's being passed to it. So unless you want to add the user credentials as actual parameters to the function call then you'll need to do something like registering the credentials globaly. This doesn't have to be in the global scope explicitly. It could be registered in some value Registry pattern instance.