google/auth
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
firebase/php-jwt | v6.10.0 | 23.55 kB | BSD-3-Clause | prod | |
guzzlehttp/guzzle | 7.8.1 | 112.34 kB | MIT | prod dev | |
guzzlehttp/promises | 2.0.2 | 25.27 kB | MIT | prod dev | |
guzzlehttp/psr7 | 2.6.2 | 76.41 kB | MIT | prod dev | |
psr/cache | 3.0.0 | 6.01 kB | MIT | prod |
The Google Auth Library for PHP, available through the GitHub repository, provides a powerful method to utilize OAuth 2.0 authorization and authentication with Google APIs. This PHP client library enables secure and efficient interaction with a variety of Google's vast services, thus streamlining the integration process.
The most common way to install and use Google Auth Library in your PHP applications is through Composer, a standard package manager for PHP projects. Firstly, Composer can be installed via a CURL command as shown in the provided code:
curl -sS https://getcomposer.org/installer | php
Following the installation of Composer, Google Auth can then be fetched using the require
command:
composer.phar require google/auth
In the Google Auth library, the focus is the application default credentials functionality, which offers a straightforward way of obtaining authorization credentials for Google API calls.
Here's a brief example of how to use this library, specifically for accessing Google Drive files in a read-only fashion:
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
// Add the path to your JSON credentials file
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');
// Define the scopes for your API call
$scopes = ['https://www.googleapis.com/auth/drive.readonly'];
// Create the middleware
$middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
$stack = HandlerStack::create();
$stack->push($middleware);
// Create the HTTP client
$client = new Client([
'handler' => $stack,
'base_uri' => 'https://www.googleapis.com',
'auth' => 'google_auth' // authorize all requests
]);
// Make your API request
$response = $client->get('drive/v2/files');
// Display the result
print_r((string) $response->getBody());
It's important to note that your service account credentials JSON file needs to be securely stored and not included in your source code.
The complete reference documentation for Google Auth Library is accessible at https://googleapis.github.io/google-auth-library-php/main/. This detailed guide encompasses all necessary information for introduction, installation, usage, various features, middleware, caching, and much more. As you navigate the complexities of authorization and authentication with Google APIs, this exhaustive resource serves as a reliable partner.