Is it possible to create a POST request using guzzle6 which has .pfx-certificate attached to it?
The documention only mentions pem-format: http://docs.guzzlephp.org/en/stable/request-options.html#cert
Is it possible to create a POST request using guzzle6 which has .pfx-certificate attached to it?
The documention only mentions pem-format: http://docs.guzzlephp.org/en/stable/request-options.html#cert
Although the documentation at http://docs.guzzlephp.org/en/stable/request-options.html#cert doesn't mention it, it seems to be possible to also use pfx-format with guzzle.
PFX certificates are used for "mutual authentications", that means, the PFX is generated with your local private key and the remote public cert.
To generate a PFX key you run:
openssl pkcs12 -inkey your_privkey.pem -in remote_pub.cert -export -out mixed.pfx
To make a request using the PFX cert, you can:
$api = new \GuzzleHttp\Client([
'base_uri' => $baseUrl,
'cert' => 'path/to/mixed.pfx',
'curl' => [CURLOPT_SSLCERTTYPE => 'P12'], // to define it's a PFX key
]);
this will work in drupal 8 too
use GuzzleHttp\Client;
// Base URI is used with relative requests
$client = new Client([
'base_uri' => 'https://www.google.com',
'cert' => 'pathtopfxflie/nameof.pfx',
'curl' => [CURLOPT_SSLCERTTYPE => 'P12']]);
$response = $client->request('METHOD', 'api path',['headers' => ['Employer' => 100]]);
//get status code using $response->getStatusCode();
$body = $response->getBody();
$arr_body = json_decode($body);