php-github-api
php-github-api copied to clipboard
Get release asset end in AccessDenied
With the GuzzleHTTP\Client it's not possible to load assets as binary, the redirect to https://objects.githubusercontent.com/ returns an error:
$token = 'example';
$client = Client::createWithHttpClient( new \GuzzleHttp\Client() );
$client->authenticate( $token, Client::AUTH_ACCESS_TOKEN );
$content = $this->client->repo()->releases()->assets()->show( $username, $name, $assetId, true );
$temp = tempnam( sys_get_temp_dir(), 'TMP_' );
file_put_contents( $temp, $content );
<Error>
<Code>AccessDenied</Code>
<Message>Multiple auth mechanisms are not allowed; please use either query parameters or an Authorization header</Message>
<Resource>github-production-release-asset-XXXXX</Resource>
</Error>
With the HttpClient\HttplugClient from Symfony it works:
...
$client = Client::createWithHttpClient( new \Symfony\Component\HttpClient\HttplugClient() );
$client->authenticate( $token, Client::AUTH_ACCESS_TOKEN );
...
The redirect-plugin uses the same client which appends the Authorization-header to the request, but the redirect-URL already contains query-parameter for authentication.