Digest authentication with Guzzle

2.7k views Asked by At

Trying to get to get JSON response from API that uses digest authentication. I am using Guzzle for the client.

This is what I have so far and doesn't seem to work. Any suggestion?

<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client([
'base_uri' => 'https://10.1.1.1',
'timeout'  => 2.0,
]);

$client->setDefaultOption('verify', false);
$client->request('POST', '/json', ['auth' => ['username', 'password', 'digest']]);
2

There are 2 answers

0
Sujan On BEST ANSWER
<?php

require 'vendor/autoload.php';
use GuzzleHttp\Client;

$client = new Client();

$query = '{"id":1}'; //json payload if any

$result = $client->request(
        'POST',
        'https://10.1.1.1/json', [
            'verify' => false,
            'auth' => ['username', 'password', 'digest'],
            'json' => json_decode($query, true),
        ]);
1
Tom On

Check if php-curl extension is installed. If not install it. For linux:

sudo apt-get install php-curl