google / auth
Google Auth Library for PHP
Requires
- php: ^8.1
- firebase/php-jwt: ^6.0||^7.0
- guzzlehttp/guzzle: ^7.8.2||^8.0
- guzzlehttp/psr7: ^2.6.3||^3.0
- psr/cache: ^2.0||^3.0
- psr/http-client: ^1.0
- psr/http-message: ^1.1||^2.0
- psr/log: ^2.0||^3.0
Requires (Dev)
- guzzlehttp/promises: ^2.0.3||^3.0
- kelvinmo/simplejwt: ^1.1.0
- phpseclib/phpseclib: ^3.0.35
- phpspec/prophecy-phpunit: ^2.1
- phpunit/phpunit: ^9.6.34
- sebastian/comparator: >=1.2.3
- squizlabs/php_codesniffer: ^4.0
- symfony/filesystem: ^6.4.39||^7.3
- symfony/process: ^6.4.41||^7.0
- webmozart/assert: ^1.11||^2.0
Suggests
- phpseclib/phpseclib: May be used in place of OpenSSL for signing strings or for token management. Please require version ^2.
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.x-dev
- v1.55.0
- v1.54.0
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.2
- v1.50.1
- v1.50.0
- v1.49.0
- v1.48.1
- v1.48.0
- v1.47.1
- v1.47.0
- v1.46.0
- v1.45.4
- v1.45.3
- v1.45.2
- v1.45.1
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.0
- v1.38.0
- 1.37.x-dev
- v1.37.2
- v1.37.1
- v1.37.0
- v1.36.0
- v1.35.0
- v1.34.0
- v1.33.0
- v1.32.1
- v1.32.0
- v1.31.0
- v1.30.0
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.0
- v1.23.1
- v1.23.0
- v1.22.0
- v1.21.1
- v1.21.0
- v1.20.1
- v1.20.0
- v1.19.1
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.3
- v1.14.2
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.1
- v1.12.0
- v1.11.1
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0
- v0.11.1
- v0.11.0
- v0.10
- v0.9
- v0.8
- v0.7
- v0.6
- v0.5
- v0.4
- v0.3
- v0.2-alpha
- v0.1-alpha
- dev-local-ecs-mock-testing
- dev-add-rab-to-external-account-authorized-user-credentials
- dev-add-x509-credential-source
- dev-refactor-access-token-verify
- dev-dirsep
- dev-remove-docs-generation
- dev-client-id-juggling
- dev-id-token-impersonation-in-tpc
- dev-logger-prototype
- dev-dev-cache-keys
- dev-cache-proto
- dev-release-please--branches--release-please-test-branch
- dev-release-please-test-branch
- dev-metrics-without-extra-trait
- dev-fix-phpseclib-lint
- dev-fix_style
- dev-auth-metrics-dev-all
- dev-add-property-typehints
- dev-add-retry
- dev-debug-request-logger
- dev-dev-logging-extra
- dev-logging-extra
This package is auto-updated.
Last update: 2026-09-21 19:40:56 UTC
README
NOTE: This repository is part of Google Cloud PHP. Any support requests, bug reports, or development contributions should be directed to that project.
Description
This is Google's officially supported PHP client library for using OAuth 2.0 authorization and authentication with Google APIs.
Installing via Composer
The recommended way to install the google auth library is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version:
composer.phar require google/auth
Application Default Credentials
This library provides an implementation of Application Default Credentials (ADC) for PHP.
Application Default Credentials provides a simple way to get authorization credentials for use in calling Google APIs, and is the recommended approach to authorize calls to Cloud APIs.
Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source for authentication to Google Cloud Platform, you must validate it before providing it to any Google API or library. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. For more information, refer to Validate credential configurations from external sources.
Set up ADC
To use ADC, you must set it up by providing credentials. How you set up ADC depends on the environment where your code is running, and whether you are running code in a test or production environment.
For more information, see Set up Application Default Credentials.
Enable the API you want to use
Before making your API call, you must be sure the API you're calling has been
enabled. Go to APIs & Auth > APIs in the
Google Developers Console and enable the APIs you'd like to
call. For the example below, you must enable the Drive API.
Call the APIs
As long as you update the environment variable below to point to your JSON credentials file, the following code should output a list of your Drive files.
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/drive.readonly']; // create 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 the request $response = $client->get('drive/v2/files'); // show the result! print_r((string) $response->getBody());