Skip to content

Commit 005f8d8

Browse files
authored
Endpoints bug fix and updates (GoogleCloudPlatform#483)
1 parent 21aa1f9 commit 005f8d8

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

endpoints/getting-started/README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,33 @@ With the API key, you can use the echo client to access the API:
5151

5252
### Using the JWT client.
5353

54-
The JWT client demonstrates how to use service accounts to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a service account. To create a service account:
54+
The JWT client demonstrates how to use service accounts to authenticate to
55+
endpoints. To use the client, you'll need both an API key (as described in the
56+
echo client section) and a service account. To create a service account:
5557

5658
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
5759
2. Click 'Create credentials'.
5860
3. Select 'Service account key'.
5961
4. In the 'Select service account' dropdown, select 'Create new service account'.
6062
5. Choose 'JSON' for the key type.
63+
6. Click on your newly created service account credentials and then click the
64+
'Download JSON' button to download a json file with your credentials. You
65+
will use this later.
6166

6267
To use the service account for authentication:
6368

64-
1. Update the `google_jwt`'s `x-google-jwks_uri` in `openapi.yaml` with your service account's email address.
69+
1. Update `YOUR-SERVICE-ACCOUNT-EMAIL` with your service account's email address
70+
in `openapi.yaml` (if you're using GKE or GCE) or `openapi-appengine.yaml`
71+
(if you're using App Engine Flex).
72+
73+
google_jwt:
74+
# Update this with your service account's email address.
75+
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL"
76+
6577
2. Redeploy your application.
6678

79+
gcloud app deploy
80+
6781
Now you can use the JWT client to make requests to the API:
6882

6983
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/service-account.json
@@ -76,16 +90,35 @@ The ID Token client demonstrates how to use user credentials to authenticate to
7690
2. Click 'Create credentials'.
7791
3. Select 'OAuth client ID'.
7892
4. Choose 'Other' for the application type.
93+
5. Click on your newly created client credentials and then click the 'Download JSON'
94+
button to download a json file with your credentials. You will use this later.
7995

8096
To use the client ID for authentication:
8197

82-
1. Update `google_id_token: x-google-audiences` in `openapi.yaml` with your client ID.
98+
1. Update `YOUR-CLIENT-ID` in with your client ID in `openapi.yaml` (if you're
99+
using GKE or GCE) or `openapi-appengine.yaml` (if you're using App Engine
100+
Flex).
101+
102+
google_id_token:
103+
# Your OAuth2 client's Client ID must be added here. You can add
104+
# multiple client IDs to accept tokens from multiple clients.
105+
x-google-jwks_uri: "YOUR-CLIENT-ID"
106+
83107
2. Redeploy your application.
84108

109+
gcloud app deploy
110+
85111
Now you can use the client ID to make requests to the API:
86112

87113
$ php endpoints.php make-request https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/client-secrets.json
88114

115+
116+
If you experience any issues, try running `gcloud endpoints configs describe` to
117+
debug the service:
118+
119+
gcloud endpoints configs describe YOUR-CONFIG-ID --service=YOUR-PROJECT-ID.appspot.com
120+
121+
89122
## Viewing the Endpoints graphs
90123

91124
By using Endpoints, you get access to several metrics that are displayed graphically in the Cloud Console.

endpoints/getting-started/app.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
// create the Silex application
2929
$app = new Application();
3030

31+
$app->get('/', function () use ($app) {
32+
// Simple echo service.
33+
$url = 'https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/endpoints/getting-started/README.md';
34+
35+
$welcome = sprintf(
36+
'

Welcome to the Endpoints getting started tutorial!

'
.
37+
'

Please see the README for instructions

'
,
38+
$url
39+
);
40+
return $welcome;
41+
});
42+
3143
$app->post('/echo', function () use ($app) {
3244
// Simple echo service.
3345
$message = $app['request']->get('message');

endpoints/getting-started/app.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
runtime: php
22
env: flex
33

4+
runtime_config:
5+
document_root: .
6+
47
endpoints_api_service:
58
# The following values are to be replaced by information from the output of
69
# 'gcloud service-management deploy openapi.yaml' command. If you have
710
# previously run the deploy command, you can list your existing configuration
811
# ids using the 'configs list' command as follows:
9-
# 'gcloud service-management configs list --service=echo-api.endpoints.[PROJECT-ID].cloud.goog'
10-
# where echo-api.endpoints.[PROJECT-ID].cloud.goog is your Endpoints service name.
12+
#
13+
# gcloud endpoints configs list --service=YOUR-PROJECT-ID.appspot.com
14+
#
1115
name: ENDPOINTS SERVICE NAME
1216
config_id: ENDPOINTS CONFIG ID

endpoints/getting-started/openapi.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,25 @@ securityDefinitions:
8383
# to sign a json web token. This is mostly used for server-to-server
8484
# communication.
8585
google_jwt:
86+
# Update this with your service account's email address.
87+
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL"
8688
authorizationUrl: ""
8789
flow: "implicit"
8890
type: "oauth2"
8991
# This must match the 'iss' field in the JWT.
9092
x-google-issuer: "jwt-client.endpoints.sample.google.com"
91-
# Update this with your service account's email address.
92-
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL"
9393
# This must match the "aud" field in the JWT. You can add multiple
9494
# audiences to accept JWTs from multiple clients.
9595
x-google-audiences: "echo.endpoints.sample.google.com"
9696
# This section configures authentication using Google OAuth2 ID Tokens.
9797
# ID Tokens can be obtained using OAuth2 clients, and can be used to access
9898
# your API on behalf of a particular user.
9999
google_id_token:
100+
# Your OAuth2 client's Client ID must be added here. You can add
101+
# multiple client IDs to accept tokens from multiple clients.
102+
x-google-audiences: "YOUR-CLIENT-ID"
100103
authorizationUrl: ""
101104
flow: "implicit"
102105
type: "oauth2"
103106
x-google-issuer: "https://accounts.google.com"
104107
x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
105-
# Your OAuth2 client's Client ID must be added here. You can add
106-
# multiple client IDs to accept tokens from multiple clients.
107-
x-google-audiences: "YOUR-CLIENT-ID"

0 commit comments

Comments
 (0)