You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add three samples:
1. Use App Engine default service account client (without key file).
2. Use non-default service account client (without key file).
3. Use Google ID token client (without key file)
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:
62
+
The JWT client demonstrates how to use a service account to authenticate to endpoints with the service account's private key file. 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:
63
63
64
64
1. Open the Credentials page of the API Manager in the [Cloud Console](https://console.cloud.google.com/apis/credentials).
65
65
2. Click 'Create credentials'.
@@ -76,7 +76,7 @@ Now you can use the JWT client to make requests to the API:
The ID Token client demonstrates how to use user credentials to authenticate to endpoints. To use the client, you'll need both an API key (as described in the echo client section) and a OAuth2 client ID. To create a client ID:
82
82
@@ -93,3 +93,69 @@ To use the client ID for authentication:
93
93
Now you can use the client ID to make requests to the API:
### Using the App Engine default service account client (no key file needed)
98
+
99
+
The App Engine default service account client demonstrates how to use the Google App Engine default service account to authenticate to endpoints.
100
+
We refer to the project that serves API requests as the server project. You also need to create a client project in the [Cloud Console](https://console.cloud.google.com). The client project is running Google App Engine standard application.
101
+
102
+
To use the App Engine default service account for authentication:
103
+
104
+
1. Update the `gae_default_service_account`'s `x-issuer` and `x-jwks_uri` in `swagger.yaml` with your client project ID.
105
+
2. Redeploy your server application.
106
+
3. Update clients/service_to_service_gae_default/main.py, replace 'YOUR-CLIENT-PROJECT-ID' and 'YOUR-SERVER-PROJECT-ID' with your client project ID and your server project ID.
107
+
4. Upload your application to Google App Engine by invoking the following command. Note that you need to provide project ID in the command because there are two projects (server and client projects) here and gcloud needs to know which project to pick.
Your client app is now deployed at https://<YOUR-CLIENT-PROJECT-ID>.appspot.com. When you access https://<YOUR-CLIENT-PROJECT-ID>.appspot.com, your client calls your server project API using
112
+
the client's service account.
113
+
114
+
### Using the service account client (no key file needed)
115
+
116
+
The service account client demonstrates how to use a non-default service account to authenticate to endpoints.
117
+
We refer to the project that serves API requests as the server project. You also need to create a client project in the [Cloud Console](https://console.cloud.google.com).
118
+
The client project is running Google App Engine standard application.
119
+
120
+
In the example, we use Google Cloud Identity and Access Management (IAM) API to create a JSON Web Token (JWT) for a service account, and use it to call an Endpoints API.
121
+
122
+
To use the client, you will need to enable "Service Account Actor" role for App Engine default service account:
123
+
1. Go to [IAM page] of your client project (https://console.cloud.google.com/iam-admin/iam).
124
+
2. For App Engine default service account, from “Role(s)” drop-down menu, select “Project”-“Service Account Actor”, and Save.
125
+
126
+
You also need to install Google API python library because the client code (main.py) uses googleapiclient,
127
+
which is a python library that needs to be uploaded to App Engine with your application code. After you run "pip install -t lib -r requirements",
128
+
Google API python client library should have already been installed under 'lib' directory. Additional information can be found
1. Update the `google_service_account`'s `x-issuer` and `x-jwks_uri` in `swagger.yaml` with your service account email.
133
+
2. Redeploy your server application.
134
+
3. Update clients/service_to_service_non_default/main.py, replace 'YOUR-SERVICE-ACCOUNT-EMAIL', 'YOUR-SERVER-PROJECT-ID' and 'YOUR-CLIENT-PROJECT-ID'
135
+
with your service account email, your server project ID, and your client project ID.
136
+
4. Upload your application to Google App Engine by invoking the following command. Note that you need to provide project ID in the command because there are two projects (server and client projects) here and gcloud needs to know which project to pick.
Your client app is now deployed at https://<YOUR-CLIENT-PROJECT-ID>.appspot.com. When you access https://<YOUR-CLIENT-PROJECT-ID>.appspot.com, your client calls your server project API using
141
+
the client's service account.
142
+
143
+
### Using the ID token client (no key file needed)
144
+
145
+
This example demonstrates how to authenticate to endpoints from Google App Engine default service account using Google ID token.
146
+
In the example, we first create a JSON Web Token (JWT) using the App Engine default service account. We then request a Google
147
+
ID token using the JWT, and call an Endpoints API using the Google ID token.
148
+
149
+
We refer to the project that serves API requests as the server project. You also need to create a client project in the [Cloud Console](https://console.cloud.google.com).
150
+
The client project is running Google App Engine standard application.
151
+
152
+
To use the client for authentication:
153
+
1. Update the `google_id_token`'s audiences, replace `YOUR-SERVER-PROJECT-ID` with your server project ID.
154
+
2. Redeploy your server application.
155
+
3. Update clients/service_to_service_google_id_token/main.py, replace 'YOUR-CLIENT-PROJECT-ID' and 'YOUR-SERVER-PROJECT-ID' with your client project ID and your server project ID.
156
+
4. Upload your application to Google App Engine by invoking the following command. Note that you need to provide project ID in the command because there are two projects (server and client projects) here and gcloud needs to know which project to pick.
Your client app is now deployed at https://<YOUR-CLIENT-PROJECT-ID>.appspot.com. When you access https://<YOUR-CLIENT-PROJECT-ID>.appspot.com, your client calls your server project API from
161
+
the client's service account using Google ID token.
0 commit comments