diff --git a/.env.example b/.env.example index b04cbdb163fd28171259ee1d8b2c8b842816743f..d840b0e0bbad8d104b50b508980a2a7ac0808bed 100644 --- a/.env.example +++ b/.env.example @@ -7,5 +7,5 @@ POSTGRES_USER=postgres POSTGRES_PASSWORD=root API_KEY=secret -REST_HOST=http://webtune-rest:8888 +REST_HOST=http://webtune-soap:8080/webtune-soap REST_KEY=apahayo \ No newline at end of file diff --git a/Service/Soap/SoapClientFactory.php b/Service/Soap/SoapClientFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..91427ce5f1caf18b042be2b1ce34c877ff27c743 --- /dev/null +++ b/Service/Soap/SoapClientFactory.php @@ -0,0 +1,36 @@ +<?php + +namespace Service\Soap; + +use Service\Soap\TokenSoap; + +use SoapClient; +use SoapHeader; + +class SoapClientFactory { + private string $wsdl; + private TokenSoap $token_gen; + + public function __construct(string $wsdl) { + $this->wsdl = $wsdl; + $this->token_gen = new TokenSoap(); + } + + public function generate_client(?string $token = null): SoapClient { + $client = new SoapClient($this->wsdl); + + if(is_null($token)){ + $token = $this->token_gen->generate_token(); + } + + $header = new SoapHeader( + "http://services.webtune.com/", + "Token", + $token + ); + + $client->__setSoapHeaders($header); + + return $client; + } +} \ No newline at end of file diff --git a/Service/Soap/SubscribeSoap.php b/Service/Soap/SubscribeSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..81b88b4fc64f843d73838ce8c7420f0ad8a55016 --- /dev/null +++ b/Service/Soap/SubscribeSoap.php @@ -0,0 +1,28 @@ +<?php + +namespace Service\Soap; + +class SubscribeSoap { + private SoapClientFactory $factory; + + public function __construct() { + $wsdl = getenv("SOAP_API"). "/services/subscription?wsdl"; + $this->factory = new SoapClientFactory($wsdl); + } + + public function is_access_permitted( + string $creator_id, + string $subscriber_id, + ?string $last_token = null + ): bool { + $soap = $this->factory->generate_client($last_token); + + return $soap->__soapCall( + "isPermittedAccess", + [ + "creator-id" => $creator_id, + "subscriber-id" => $subscriber_id, + ] + ); + } +} diff --git a/Service/Soap/TokenSoap.php b/Service/Soap/TokenSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..de5d54d3e592b043b2814fa04b052dcf66b552a9 --- /dev/null +++ b/Service/Soap/TokenSoap.php @@ -0,0 +1,34 @@ +<?php + +namespace Service\Soap; + +use SoapClient; + +class TokenSoap { + private SoapClient $soap; + + static string | null $token; + static int $exp_time; + + public function __construct() { + $soap_key = getenv("SOAP_KEY"); + $wsdl = getenv("SOAP_API")."/services/security?wsdl"; + + $this->soap = new SoapClient($wsdl, [ + "stream_context" => stream_context_create([ + "http" => [ + "header" => "X-API-KEY: $soap_key", + ], + ]), + ]); + } + + public function generate_token(): string { + $token = $this->soap->__soapCall( + "getToken", + [] + ); + + return $token; + } +}