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'] ) { public function __construct( private string $token, private string $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)); // var_dump($params, $this, $this->getAuthClient()); // // $this->getAuthClient()->request( // 'POST', // $this->getUrl( // $this->clientConfig->get()->endpoint, // "/api/v1/autoprospect/orderprospect" // ), [ // 'json' => $params // ] // ); return false; } }