Download the PHP package google/auth without Composer
On this page you can find all versions of the php package google/auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package auth
Google Auth Library for PHP
- Reference Docs
- Tim Emiola
- Stanley Cheung
- Brent Shaffer
- Copyright © 2015 Google, Inc.
- Apache 2.0
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.
Next, run the Composer command to install the latest stable version:
Application Default Credentials
This library provides an implementation of application default credentials for PHP.
The Application Default Credentials provide a simple way to get authorization credentials for use in calling Google APIs.
They are best suited for cases when the call needs to have the same identity and authorization level for the application independent of the user. This is the recommended approach to authorize calls to Cloud APIs, particularly when you're building an application that uses Google Compute Engine.
Download your Service Account Credentials JSON file
Application Default Credentials, You first need to download a set of
JSON credentials for your project. Go to APIs & Services > Credentials in
the Google Developers Console and select
Service account from the Add credentials dropdown.
This file is your only copy of these credentials. It should never be committed with your source code, and should be stored securely.
Once downloaded, store the path to this file in the
GOOGLE_APPLICATION_CREDENTIALS environment variable.
putenvfunction is just one way to set an environment variable. Consider using
.htaccessor apache configuration files as well.
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
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.
Guzzle 5 Compatibility
If you are using Guzzle 5, replace the
create middleware and
create the HTTP Client steps with the following:
Call using an ID Token
If your application is running behind Cloud Run, or using Cloud Identity-Aware
Proxy (IAP), you will need to fetch an ID token to access your application. For
this, use the static method
For invoking Cloud Run services, your service account will need the
Cloud Run Invoker
For invoking Cloud Identity-Aware Proxy, you will need to pass the Client ID used when you set up your protected resource as the target audience. See how to secure your IAP app with signed headers.
Call using a specific JSON key
If you want to use a specific JSON key instead of using
GOOGLE_APPLICATION_CREDENTIALS environment variable, you can
Call using Proxy-Authorization Header
If your application is behind a proxy such as Google Cloud IAP,
and your application occupies the
Authorization request header,
you can include the ID token in a
header instead. If a valid ID token is found in a
IAP authorizes the request with it. After authorizing the request, IAP passes
the Authorization header to your application without processing the content.
For this, use the static method
If you are using Google ID tokens to authenticate users, use
Google\Auth\AccessToken class to verify the ID token:
If your app is running behind Google Identity-Aware Proxy (IAP), you can verify the ID token coming from the IAP server by pointing to the appropriate certificate URL for IAP. This is because IAP signs the ID tokens with a different key than the Google Identity service:
This library is licensed under Apache 2.0. Full license text is available in COPYING.