wapacro / az-keyvault-php

Library to easily work with Azure Key Vault using managed identities
https://packagist.org/packages/wapacro/az-keyvault-php
MIT License
17 stars 15 forks source link

setSecret() does not work (Please use the "form_params") #16

Open fracz opened 2 years ago

fracz commented 2 years ago

When I try to use the setSecret(string, string) method, I receive the following error message.

Passing in the "body" request option as an array to send a request is not supported. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or the "multipart" request option to send a multipart/form-data request.

Possibly related with https://stackoverflow.com/a/34411797/878514

Sundwalltanner commented 9 months ago

I know this is old, but I ended up fixing this by overwriting the post function like this:

class CloudAwareKeyVaultClient extends AzKeyVault\Client
{
    public function post(string $url, array $body, string $accessToken = null, string $accessTokenHeader = 'Authorization', string $apiVersion = self::VAULT_API_VERSION)
    {
        $url = Spatie\Url\Url::fromString($url)->withQueryParameter('api-version', $apiVersion);
        return json_decode($this->client->put($url, [
            'headers' => [$accessTokenHeader => $accessToken ?? $this->accessToken],
            'json' => $body,
        ])->getBody());
    }
}