clientConfig = $clientConfig; $this->client = HttpClient::create( [ 'headers' => [ 'cache-control' => 'no-cache', ] ] ); $this->auth = $this->authenticate(); } private function getUrl(string $endpoint, string $path): string { return sprintf( 'https://%s.azurewebsites.net/%s', rtrim($endpoint, '/'), ltrim($path, '/') ); } public function authenticate(): object { $request = $this->client->request( 'POST', $this->getUrl($this->clientConfig->get()->auth_endpoint, '/connect/token'), [ 'body' => [ 'grant_type' => 'client_credentials', 'client_id' => $this->clientConfig->get()->id, 'client_secret' => $this->clientConfig->get()->secret ] ] ); $result = $request->toArray(); return new class ( $result['access_token'], $result['token_type'] ) { private string $token; private string $type; public function __construct( string $token, string $type ) { $this->token = $token; $this->type = $type; } public function getHeader(): string { return sprintf("%s %s", $this->type, $this->token); } }; } private function getAuthClient(): HttpClientInterface { return $this->client->withOptions([ 'headers' => [ 'Authorization' => $this->auth->getHeader(), ] ]); } public function orderProspectus( Prospectus $prospectus ): bool { $ret = $this->getAuthClient()->request( "POST", 'https://uat-process-externalpart.azurewebsites.net/api/v1/autoprospect/orderprospect', [ 'json' => $prospectus->toPostParams(), ] ); var_dump($ret->getContent(false)); return false; } }