diff --git a/docs/client/authentication.md b/docs/client/authentication.md index 12ba002..97576a0 100644 --- a/docs/client/authentication.md +++ b/docs/client/authentication.md @@ -42,6 +42,12 @@ Like Wss/Wsse it uses the same package: ->withWsa() ->call(...) +You can also use the 2005 version of Wsa with + + $response = Soap::baseWsdl(...) + ->withWsa2005() + ->call(...) + ### DHL Cis Authentication DHL uses his own authentication header diff --git a/src/SoapClient.php b/src/SoapClient.php index 3d60220..7da51f2 100644 --- a/src/SoapClient.php +++ b/src/SoapClient.php @@ -38,6 +38,7 @@ use Soap\Psr18Transport\Psr18Transport; use Soap\Psr18Transport\Wsdl\Psr18Loader; use Soap\Psr18WsseMiddleware\WsaMiddleware; +use Soap\Psr18WsseMiddleware\WsaMiddleware2005; use Soap\Wsdl\Loader\FlatteningLoader; use Soap\Wsdl\Loader\StreamWrapperLoader; @@ -248,6 +249,18 @@ public function withWsa() return $this; } + /** + * @return $this + */ + public function withWsa2005() + { + $this->middlewares = array_merge_recursive($this->middlewares, [ + new WsaMiddleware2005(), + ]); + + return $this; + } + public function withWsse(array $options): static { $this->middlewares = array_merge_recursive($this->middlewares, [ diff --git a/tests/Unit/SoapClientTest.php b/tests/Unit/SoapClientTest.php index a47b026..b35d10b 100644 --- a/tests/Unit/SoapClientTest.php +++ b/tests/Unit/SoapClientTest.php @@ -70,6 +70,22 @@ public function testWsseWithWsaCall() self::assertTrue($response->ok()); } + public function testWsseWithWsa2005Call() + { + Soap::fake(); + ray()->showSoapClientRequests(); + $client = Soap::baseWsdl(dirname(__DIR__, 1).'/Fixtures/Wsdl/weather.wsdl')->withWsse([ + 'userTokenName' => 'Test', + 'userTokenPassword' => 'passwordTest', + 'mustUnderstand' => false, + ])->withWsa2005(); + $response = $client->GetWeatherInformation(); + Soap::assertSent(function (Request $request) { + return ! Str::contains($request->xmlContent(), 'mustUnderstand'); + }); + self::assertTrue($response->ok()); + } + public function testArrayAccessResponse() { Soap::fakeSequence()->push('test');