|
18 | 18 | namespace Google\Cloud\Samples\Auth; |
19 | 19 |
|
20 | 20 | use Google\Auth\Credentials\GCECredentials; |
| 21 | +use google\appengine\api\app_identity\AppIdentityService; |
21 | 22 |
|
22 | | -// Install composer dependencies with "composer install" |
23 | | -// @see http://getcomposer.org for more information. |
24 | 23 | require __DIR__ . '/vendor/autoload.php'; |
25 | 24 |
|
26 | | -print('<pre>'); |
27 | | -if (GCECredentials::onGce()) { |
28 | | - printf("Buckets retrieved using the cloud client library:\n"); |
29 | | - auth_cloud_explicit_compute_engine(getenv('GCLOUD_PROJECT')); |
30 | | - printf("\n"); |
31 | | - printf("Buckets retrieved using the api client:\n"); |
32 | | - auth_api_explicit_compute_engine(getenv('GCLOUD_PROJECT')); |
33 | | -} else { |
34 | | - printf("Buckets retrieved using the cloud client library:\n"); |
35 | | - auth_cloud_explicit_app_engine(getenv('GCLOUD_PROJECT')); |
36 | | - printf("\n"); |
37 | | - printf("Buckets retrieved using the api client:\n"); |
38 | | - auth_api_explicit_app_engine(getenv('GCLOUD_PROJECT')); |
39 | | -} |
40 | | -print('</pre>'); |
| 25 | +$onGce = GCECredentials::onGce(); |
| 26 | +$projectId = $onGce |
| 27 | + ? getenv('GCLOUD_PROJECT') |
| 28 | + : AppIdentityService::getApplicationId(); |
| 29 | +?> |
| 30 | + |
| 31 | +<h1>Buckets retrieved using the cloud client library:</h1> |
| 32 | +<pre> |
| 33 | +<?php if ($onGce): ?> |
| 34 | +<?php auth_cloud_explicit_compute_engine($projectId) ?> |
| 35 | +<?php else: ?> |
| 36 | +<?php auth_cloud_explicit_app_engine($projectId) ?> |
| 37 | +<?php endif ?> |
| 38 | +</pre> |
| 39 | + |
| 40 | +<h1>Buckets retrieved using the api client:</h1> |
| 41 | +<pre> |
| 42 | +<?php if ($onGce): ?> |
| 43 | +<?php auth_api_explicit_compute_engine($projectId) ?> |
| 44 | +<?php else: ?> |
| 45 | +<?php auth_api_explicit_app_engine($projectId) ?> |
| 46 | +<?php endif ?> |
| 47 | +</pre> |
0 commit comments