Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass credentials to client? #61

Closed
etcware opened this issue Feb 2, 2022 · 2 comments
Closed

How to pass credentials to client? #61

etcware opened this issue Feb 2, 2022 · 2 comments

Comments

@etcware
Copy link

etcware commented Feb 2, 2022

I need to pass credentials to soap client, is there an example to do this?

@goetas
Copy link
Member

goetas commented Feb 4, 2022

you need to pass a custom message factory to the client factory.

someting like

use Http\Discovery\Psr17FactoryDiscovery;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;

// get your factory , as example $factory = new ClientFactory($metadata, $serializer);

$baseMessageFactory = Psr17FactoryDiscovery::findRequestFactory();

$myMessageFactory = new MyMessageFactory($baseMessageFactory);
$factory->setMessageFactory($messageFactory);

class MyMessageFactory implements RequestFactoryInterface
{
    private RequestFactoryInterface $parentFactory;
    public function __construct(RequestFactoryInterface $parentFactory): RequestInterface
    {
        $this->parentFactory = $parentFactory;
    }

    public function createRequest(string $method, $uri): RequestInterface
    {
        $message = $this->parentFactory->createRequest($method, $uri);
        $message = $message->withHeaders(...); // add here your auth headers as example
        return $message;
    }
}

@goetas goetas closed this as completed Feb 4, 2022
@etcware
Copy link
Author

etcware commented Feb 8, 2022

Thanks, but I have an additional problem, I cannot generate the metadata because also to access to WSDL during metadata generation needs credentials...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants