The best way and recommended to handle and manage auth credentials is to use the official tools offered by Google. Use Auth Library for PHP , then integrate it with the HTTP client that you use.
The scope for Cloud API is: https://www.googleapis.com/auth/cloud-platform
For Example:
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
// specify the path to your application credentials
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
// define the scopes for your API call
$scopes = ['https://www.googleapis.com/auth/cloud-platform'];
// create middleware
$middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
$stack = HandlerStack::create();
$stack->push($middleware);
// create the HTTP client
$client = new Client([
'handler' => $stack,
'base_uri' => 'https://LOCATION-documentai.googleapis.com',
'auth' => 'google_auth' // authorize all requests
]);
// make the request
$response = $client->get('v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID:method');