Skip to content

Commit b497de5

Browse files
committed
Added api samples and added support to deploy to App Engine
1 parent f178b59 commit b497de5

12 files changed

+574
-380
lines changed

auth/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ methods will work on any Google Cloud API.
2525
```
2626
auth-cloud-implicit Authenticate to a cloud client library using a service account implicitly.
2727
auth-cloud-explicit Authenticate to a cloud client library using a service account explicitly.
28+
auth-api-implicit Authenticate to a cloud API using a service account implicitly.
29+
auth-api-explicit Authenticate to a cloud API using a service account explicitly.
2830
```
2931
6. The following commands are available but will throw a ServiceException when
3032
run from command-line. The Compute Engine method only works on Compute Engine,
@@ -33,8 +35,17 @@ method only works on App Engine Standard.
3335
```
3436
auth-cloud-explicit-compute-engine Authenticate to a cloud client library using Compute Engine credentials explicitly.
3537
auth-cloud-explicit-app-engine Authenticate to a cloud client library using App Engine Standard credentials explicitly.
38+
auth-api-explicit-compute-engine Authenticate to a cloud API using Compute Engine credentials explicitly.
39+
auth-api-explicit-app-engine Authenticate to a cloud API using App Engine Standard credentials explicitly.
3640
```
37-
7. Run `php auth.php COMMAND --help` to print information about the usage of each command.
41+
7. You can test the samples that use Compute Engine / App Engine credentials by
42+
deploying to either App Engine Flexible (which allows usage of Compute Engine
43+
credentials since App Engine Flexible apps run on Compute Engine instances) or
44+
App Engine Standard. If you are deploying to App Engine Standard, first open
45+
`app-standard.yaml` and set the value of `GCLOUD_PROJECT` to your project ID.
46+
Run either `gcloud app deploy app-standard.yaml` or `gcloud app deploy app-flex.yaml`.
47+
48+
8. Run `php auth.php COMMAND --help` to print information about the usage of each command.
3849

3950
## Contributing changes
4051

auth/app-flex.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
runtime: php
2+
env: flex
3+
4+
runtime_config:
5+
document_root: .

auth/app-standard.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtime: php55
2+
api_version: 1
3+
threadsafe: true
4+
5+
handlers:
6+
- url: /.*
7+
script: index.php
8+
9+
env_variables:
10+
GCLOUD_PROJECT: your-project-id

auth/auth.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,79 @@
9393
})
9494
);
9595

96+
// Create auth-api-implicit Command.
97+
$application->add((new Command('auth-api-implicit'))
98+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
99+
->setDescription('Authenticate to a cloud API using a service account implicitly.')
100+
->setHelp(<<
101+
The %command.name% command authenticates to a cloud API using a
102+
service account implicitly.
103+
104+
php %command.full_name%
105+
106+
EOF
107+
)
108+
->setCode(function ($input, $output) {
109+
auth_api_implicit($input->getArgument('projectId'));
110+
})
111+
);
112+
113+
// Create auth-api-explicit Command.
114+
$application->add((new Command('auth-api-explicit'))
115+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
116+
->addArgument('serviceAccountPath', InputArgument::REQUIRED, 'Path to your service account.')
117+
->setDescription('Authenticate to a cloud API using a service account explicitly.')
118+
->setHelp(<<
119+
The %command.name% command authenticates to a cloud API using a
120+
service account implicitly.
121+
122+
php %command.full_name%
123+
124+
EOF
125+
)
126+
->setCode(function ($input, $output) {
127+
$projectId = $input->getArgument('projectId');
128+
$serviceAccountPath = $input->getArgument('serviceAccountPath');
129+
auth_api_explicit($projectId, $serviceAccountPath);
130+
})
131+
);
132+
133+
// Create auth-api-explicit-compute-engine Command.
134+
$application->add((new Command('auth-api-explicit-compute-engine'))
135+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
136+
->setDescription('Authenticate to a cloud API using Compute Engine credentials explicitly.')
137+
->setHelp(<<
138+
The %command.name% command authenticates to a cloud API using
139+
Compute Engine credentials explicitly.
140+
141+
php %command.full_name%
142+
143+
EOF
144+
)
145+
->setCode(function ($input, $output) {
146+
$projectId = $input->getArgument('projectId');
147+
auth_api_explicit_compute_engine($projectId);
148+
})
149+
);
150+
151+
// Create auth-api-explicit-app-engine Command.
152+
$application->add((new Command('auth-api-explicit-app-engine'))
153+
->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID')
154+
->setDescription('Authenticate to a cloud API using App Engine Standard credentials explicitly.')
155+
->setHelp(<<
156+
The %command.name% command authenticates to a cloud API using
157+
Compute Engine credentials explicitly.
158+
159+
php %command.full_name%
160+
161+
EOF
162+
)
163+
->setCode(function ($input, $output) {
164+
$projectId = $input->getArgument('projectId');
165+
auth_api_explicit_compute_engine($projectId);
166+
})
167+
);
168+
96169
if (getenv('PHPUNIT_TESTS') === '1') {
97170
return $application;
98171
}

auth/composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"silex/silex": "^1.3",
3+
"google/apiclient": "^2.1",
44
"google/cloud-storage": "^1.0",
55
"paragonie/random_compat": "^2.0",
66
"symfony/console": " ^3.0",
@@ -14,7 +14,11 @@
1414
"src/auth_cloud_implicit.php",
1515
"src/auth_cloud_explicit.php",
1616
"src/auth_cloud_explicit_compute_engine.php",
17-
"src/auth_cloud_explicit_app_engine.php"
17+
"src/auth_cloud_explicit_app_engine.php",
18+
"src/auth_api_implicit.php",
19+
"src/auth_api_explicit.php",
20+
"src/auth_api_explicit_compute_engine.php",
21+
"src/auth_api_explicit_app_engine.php"
1822
]
1923
},
2024
"require-dev": {

0 commit comments

Comments
 (0)