Skip to content

Commit

Permalink
Removed reduntant example from the AUTHENTICATION.md file and update …
Browse files Browse the repository at this point in the history
…the README.md file
  • Loading branch information
Hectorhammett committed Nov 8, 2024
1 parent a94c0eb commit 67ae9dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
36 changes: 4 additions & 32 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, see Credential lookup.
To review all of your authentication options, [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 All @@ -23,9 +23,8 @@ The Google Cloud PHP library provides several mechanisms to configure your syste
### Google Cloud Platform environments

While running on Google Cloud Platform environments such as Google Compute Engine, Google App Engine
and Google Kubernetes Engine, no extra work is needed. The **Project ID** and **Credentials** and
are discovered automatically from the attached service account. Code should be written as if already
authenticated.
and Google Kubernetes Engine, no extra work is needed. The **Credentials** and are discovered
automatically from the attached service account. Code should be written as if already authenticated.

For more information, see
[Set up ADC for Google Cloud services](https://cloud.google.com/docs/authentication/provide-credentials-adc#attached-sa).
Expand All @@ -39,7 +38,7 @@ your environemnt variables are set in PHP, they must use
```php
putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ . '/your-credentials-file.json');
```
The **Project ID** and **Credentials JSON** can be placed in environment variables instead of
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:
Expand Down Expand Up @@ -82,33 +81,6 @@ $video = new VideoIntelligenceServiceClient([
]);
```

However, some clients use the `keyFile` or `keyFilePath` option:

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

use Google\Cloud\Storage\StorageClient;

// Authenticating with keyfile data.
$storage = new StorageClient([
'keyFile' => json_decode(file_get_contents('/path/to/keyfile.json'), true)
]);

// Authenticating with a keyfile path.
$storage = new StorageClient([
'keyFilePath' => '/path/to/keyfile.json'
]);

// Providing the Google Cloud project ID.
$storage = new StorageClient([
'projectId' => 'myProject'
]);
```

Check the [client documentation][php-ref-docs] for the client library you're using.

[php-ref-docs]: https://cloud.google.com/php/docs/reference

### Local ADC file

This option allows for an easy way to authenticate in a local environment during development. If
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ If you need support for other Google APIs, please check out the [Google APIs Cli

## Quickstart

It is required to have the credentials configured to make requests to the api using the clients. In
this guide we'll focus on how to configure your client for local development using the Google Cloud
CLI (`gcloud`).
In this guide we'll focus on how to configure your client for local development using the Google
Cloud CLI (`gcloud`).

### For local development:
* Install the Google Cloud CLI.
Expand Down Expand Up @@ -52,6 +51,8 @@ Linux and MacOS:
$HOME/.config/gcloud/application_default_credentials.json
```

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

### Instantiating the client
Once we have the `application_default_credentials.json` that we created on the previous step now we
can instantiate a client which internally using the Google Auth library will take that file and use
Expand Down Expand Up @@ -114,9 +115,13 @@ for each service.

### Authentication

Authentication is handled by the client library automatically. You just need to provide the authentication details when creating a client. Generally, authentication is accomplished using a Service Account. For more information on obtaining Service Account credentials, see our [Authentication Guide](https://cloud.google.com/docs/authentication/production#manually).
Authentication is handled by the client once the environment is configured. Once youre credentials are created


You just need to provide the authentication details when creating a client. Generally, authentication is accomplished using a Service Account. For more information on obtaining Service Account credentials see our [Authentication Guide](https://cloud.google.com/docs/authentication/production#manually).

Once you've obtained your credentials file, it may be used to create an authenticated client.
#### Note:
Some clients accept the `keyFilePath` and `keyFile` configuration options pointing to the credentials file:

```php
require 'vendor/autoload.php';
Expand All @@ -133,6 +138,16 @@ $cloud = new StorageClient([
'keyFile' => json_decode(file_get_contents('/path/to/keyfile.json'), true)
]);
```
A list of clients that accept these parameters are:
- [Bigtable](https://github.com/googleapis/google-cloud-php-bigtable)
- [Spanner](https://github.com/googleapis/google-cloud-php-spanner)
- [Firestore](https://github.com/googleapis/google-cloud-php-firestore)
- [Datastore](https://github.com/googleapis/google-cloud-php-datastore)
- [Pubsub](https://github.com/googleapis/google-cloud-php-pubsub)

We recommend to visit the Check the [client documentation][php-ref-docs] for the client library you're using for more in depth information.

[php-ref-docs]: https://cloud.google.com/php/docs/reference

If you do not wish to embed your authentication information in your application code, you may also make use of [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).

Expand Down

0 comments on commit 67ae9dc

Please sign in to comment.