Skip to content

Commit

Permalink
Update the README and AUTHENTICATION
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Nov 13, 2024
1 parent 67ae9dc commit 05d8f17
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
26 changes: 20 additions & 6 deletions AUTHENTICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The recommended way to authenticate to the Google Cloud PHP library is to use
[Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials),
which discovers your credentials automatically, based on the environment where your code is running.
To review all of your authentication options, [Credential Lookup](#credential-lookup).
To review all of your authentication options see [Credential Lookup](#credential-lookup).

For more information about authentication at Google, see [the authentication guide](https://cloud.google.com/docs/authentication).
Specific instructions and environment variables for each individual service are linked from the README documents listed below for each service.
Expand Down Expand Up @@ -41,11 +41,6 @@ putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ . '/your-credentials-file.jso
The **Credentials JSON** can be placed in environment variables instead of
declaring them directly in code.

Here are the environment variables that Google Cloud PHP checks for project ID:

1. `GOOGLE_CLOUD_PROJECT`
2. `GCLOUD_PROJECT` (deprecated)

Here are the environment variables that Google Cloud PHP checks for credentials:

1. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
Expand All @@ -59,6 +54,25 @@ Note: Service account keys are a security risk if not managed correctly. You sho
[choose a more secure alternative to service account keys](https://cloud.google.com/docs/authentication#auth-decision-tree)
whenever possible.

### Project ID detection

Some libraries support setting up the project ID via the `GOOGLE_CLOUD_PROJECT` environment variable.
```php
putenv("GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>");
```
The libraries that support this environment variable are:
- Bigtable
- PubSub
- Storage
- Spanner
- BigQuery
- Datastore
- Firestore
- Debugger
- Logging
- Trace
- Translate

### Client Authentication

Each Google Cloud PHP client may be authenticated in code when creating a client library instance.
Expand Down
53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ PHP Version | Status

View the [list of supported APIs and Services](https://cloud.google.com/php/docs/reference).

If you need support for other Google APIs, please check out the [Google APIs Client Library for PHP](https://github.com/google/google-api-php-client).
If you need support for other Google APIs, please check out the
[Google APIs Client Library for PHP](https://github.com/google/google-api-php-client).

We recommend installing individual component packages. A list of available packages can be found on
[Packagist](https://packagist.org/search/?q=google%2Fcloud-).

For example:
```sh
$ composer require google/cloud-storage
$ composer require google/cloud-bigquery
$ composer require google/cloud-datastore
```

## Quickstart

Expand Down Expand Up @@ -53,15 +64,20 @@ $HOME/.config/gcloud/application_default_credentials.json

To read more about Authentication, see [AUTHENTICATION.md](AUTHENTICATION.md)

### Installing a client
Install the Google Translate client library with composer
```sh
composer install google/cloud-translate
```
**Note**:For this example, we are using the Google Translate client library. Check the
[the complete list of packages](https://cloud.google.com/php/docs/reference/) to find your required
library.

### Instantiating the client
Once we have the `application_default_credentials.json` that we created on the previous step now we
Once we have the `application_default_credentials.json` and the client installed now we
can instantiate a client which internally using the Google Auth library will take that file and use
it to authenticate your requests:

**Note**: You can install the Google Translate client library by running `composer install google/cloud-translate`.
See the [README.md](README.md) for further instructions, or browse
[the complete list of packages](https://cloud.google.com/php/docs/reference/).

```php
require_once 'vendor/autoload.php';

Expand All @@ -88,30 +104,13 @@ var_dump($response->getTranslations()[0]);
// }

```
This quicksetup is built with local development in mind, the steps for deploying your project are
This quickstart is built with local development in mind. The steps for deploying your project are
different depending on the environment you use. Here we provide some basic instruction in how to get
started with deployment of your project:

### GCP deployment:
* Use the metadata server instead of a credentials file.
- More information about the usage of the metadata server
[here](https://cloud.google.com/compute/docs/metadata/overview)
* Instantiate a client.

### Server deployment:
* Generate a credentials file.
- We recommend using a Service Account instead of the personal account credentials. More
information [here](https://cloud.google.com/iam/docs/service-accounts-create)
* Set the GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to your credentials file.
* Instantiate a client.

This quickstart guide is meant to be used as a quick and easy way to start development and get
started on how you can authenticate your requests.

For more information about authentication at Google, see
[the authentication guide](https://cloud.google.com/docs/authentication). Specific instructions and
environment variables for each individual service are linked from the README documents listed below
for each service.
* For applications running on Google Cloud Platform (for example, in Google Compute Engine, Google App Engine, Google Kubernetes Engine, and Google Cloud Functions), applications are automatically authenticated using the Metadata Server. For more information, see [About VM Metadata](https://cloud.google.com/compute/docs/metadata/overview)
* For applications running elsewhere, it is recommended to [create a Service Account](https://cloud.google.com/iam/docs/service-accounts-create) and enable [Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation).
* It is also possible to authenticate using [Service Account Keys](https://cloud.google.com/iam/docs/migrate-from-service-account-keys). Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to your credentials file.

### Authentication

Expand Down

0 comments on commit 05d8f17

Please sign in to comment.