Skip to content

Commit 6bc9e7f

Browse files
authored
docs: update use of credentials client option (#8750)
* docs: update use of credentials client option * fix fixtures
1 parent 21adf3d commit 6bc9e7f

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

AUTHENTICATION.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,23 @@ The libraries that support this environment variable are:
7575
### Client Authentication
7676

7777
Each Google Cloud PHP client may be authenticated in code when creating a client library instance.
78-
79-
Most clients use the `credentials` option for providing credentials as a constructor option:
78+
Most clients use the `credentials` option for providing explicit credentials:
8079

8180
```php
8281
use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient;
8382

84-
// Authenticating with keyfile data.
85-
$video = new VideoIntelligenceServiceClient([
86-
'credentials' => json_decode(file_get_contents('/path/to/credential-file.json'), true)
87-
]);
83+
$scope = ['https://www.googleapis.com/auth/cloud-platform'];
84+
$keyFile = json_decode(file_get_contents('/path/to/service-account.json'), true);
8885

89-
// Authenticating with a keyfile path.
86+
// Authenticating with keyfile data.
87+
$credentials = new ServiceAccountCredentials($scope, $keyFile);
9088
$video = new VideoIntelligenceServiceClient([
91-
'credentials' => '/path/to/credential-file.json'
89+
'credentials' => $credentials,
9290
]);
9391
```
9492

9593
#### Note:
96-
Some clients accept the `keyFilePath` and `keyFile` configuration options pointing to the credentials
97-
file. However, both of these options are deprecated in favor of using the `credentialsFetcher`
98-
option or
99-
[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
94+
Some clients use the `credentialsFetcher` client option instead:
10095

10196
```php
10297
require 'vendor/autoload.php';
@@ -105,6 +100,7 @@ use Google\Cloud\Storage\StorageClient;
105100
use Google\Auth\Credentials\ServiceAccountCredentials;
106101

107102
// Create the service account credentials and pass them in using the "credentialsFile" option
103+
$scope = ['https://www.googleapis.com/auth/devstorage.read_only'];
108104
$keyFile = json_decode(file_get_contents('/path/to/keyfile.json'), true);
109105
$storage = new StorageClient([
110106
'credentialsFetcher' => new ServiceAccountCredentials($scopes, $keyFile),

dev/tests/fixtures/docfx/ProductNeutralGuides/authentication.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,23 @@ The libraries that support this environment variable are:
7575
### Client Authentication
7676

7777
Each Google Cloud PHP client may be authenticated in code when creating a client library instance.
78-
79-
Most clients use the `credentials` option for providing credentials as a constructor option:
78+
Most clients use the `credentials` option for providing explicit credentials:
8079

8180
```php
8281
use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient;
8382

84-
// Authenticating with keyfile data.
85-
$video = new VideoIntelligenceServiceClient([
86-
'credentials' => json_decode(file_get_contents('/path/to/credential-file.json'), true)
87-
]);
83+
$scope = ['https://www.googleapis.com/auth/cloud-platform'];
84+
$keyFile = json_decode(file_get_contents('/path/to/service-account.json'), true);
8885

89-
// Authenticating with a keyfile path.
86+
// Authenticating with keyfile data.
87+
$credentials = new ServiceAccountCredentials($scope, $keyFile);
9088
$video = new VideoIntelligenceServiceClient([
91-
'credentials' => '/path/to/credential-file.json'
89+
'credentials' => $credentials,
9290
]);
9391
```
9492

9593
#### Note:
96-
Some clients accept the `keyFilePath` and `keyFile` configuration options pointing to the credentials
97-
file. However, both of these options are deprecated in favor of using the `credentialsFetcher`
98-
option or
99-
[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
94+
Some clients use the `credentialsFetcher` client option instead:
10095

10196
```php
10297
require 'vendor/autoload.php';
@@ -105,6 +100,7 @@ use Google\Cloud\Storage\StorageClient;
105100
use Google\Auth\Credentials\ServiceAccountCredentials;
106101

107102
// Create the service account credentials and pass them in using the "credentialsFile" option
103+
$scope = ['https://www.googleapis.com/auth/devstorage.read_only'];
108104
$keyFile = json_decode(file_get_contents('/path/to/keyfile.json'), true);
109105
$storage = new StorageClient([
110106
'credentialsFetcher' => new ServiceAccountCredentials($scopes, $keyFile),

0 commit comments

Comments
 (0)