| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This sample demonstrates how to use Google Cloud Endpoints using Python.
For a complete walkthrough showing how to run this sample in different environments, see the Google Cloud Endpoints Quickstarts.
This sample consists of two parts:
Install all the dependencies:
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txtRun the application:
$ python main.pyWith the app running locally, you can execute the simple echo client using:
$ python clients/echo-client.py http://localhost:8080 APIKEY helloworldThe APIKEY doesn't matter as the endpoint proxy is not running to do authentication.
See the Google Cloud Endpoints Quickstarts.
With the project deployed, you'll need to create an API key to access the API.
With the API key, you can use the echo client to access the API:
$ python clients/echo-client.py https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY helloworldThe 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:
To use the service account for authentication:
Now you can use the JWT client to make requests to the API:
$ python clients/google-jwt-client.py https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/service-account.jsonThe 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:
To use the client ID for authentication:
Now you can use the client ID to make requests to the API:
$ python clients/google-id-token-client.py https://YOUR-PROJECT-ID.appspot.com YOUR-API-KEY /path/to/client-id.jsonThe App Engine default service account client demonstrates how to use the Google App Engine default service account to authenticate to endpoints. 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. The client project is running Google App Engine standard application.
To use the App Engine default service account for authentication:
$ gcloud app deploy app.yaml --project=YOUR-CLIENT-PROJECT-IDYour 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 the client's service account.
The service account client demonstrates how to use a non-default service account to authenticate to endpoints. 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. The client project is running Google App Engine standard application.
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.
To use the client, you will need to enable "Service Account Actor" role for App Engine default service account:
You also need to install Google API python library because the client code (main.py) uses googleapiclient, 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", Google API python client library should have already been installed under 'lib' directory. Additional information can be found here.
To use the client for authentication:
$ gcloud app deploy app.yaml --project=YOUR-CLIENT-PROJECT-IDYour 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 the client's service account.
This example demonstrates how to authenticate to endpoints from Google App Engine default service account using Google ID token. In the example, we first create a JSON Web Token (JWT) using the App Engine default service account. We then request a Google ID token using the JWT, and call an Endpoints API using the Google ID token.
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. The client project is running Google App Engine standard application.
To use the client for authentication:
$ gcloud app deploy app.yaml --project=YOUR-CLIENT-PROJECT-IDYour 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 the client's service account using Google ID token.
| Back | FazBrowse Home | New Git URL |