Before users or applications can use the Google App Engine Admin API, you as a Google Cloud Platform project owner must first enable the API in your project and then create credentials that users or applications can use to authorize HTTP requests.
For example, an owner must first create an initial Cloud Platform project and then create credentials in that project before anyone can send HTTP requests to the Admin API. After the owner sets up and configures the initial project, that project can then be used for administrative purposes to programmatically create and manage other resources, for example:
- Creating other Cloud Platform projects.
- Creating App Engine applications for all newly created projects.
- Deploying app versions to newly created App Engine applications.
- Managing resources in all of the versions that you deployed.
Before you begin
To complete the following task, you must be an owner of the Cloud Platform project where you want to enable the Admin API for users and applications to access.
Configuring your project and creating credentials
To configure your Cloud Platform project and create credentials:
Enable both the Google App Engine Admin API and Google Cloud Storage API in your Cloud Platform project:
Create credentials that users and applications use to access the Admin API in your project.
To create credentials, review the Google Cloud Platform Auth Guide and then choose the OAuth 2.0 authorization flow that meets your app's requirements.
To demonstrate an authentication flow, the examples below use the client-side
OAuth 2.0 flow to obtain a token. The token is used to authorize requests to the
Admin API using the cURL command-line tool to deploy the example
app to the App Engine application of the project
In this example, the client-side authorization flow known as the implicit grant flow, requires the user to authorize the client application for access to the Admin API on behalf of the user. The access token that is returned is valid for approximately 60 minutes or generally while the user is active on your application.
Tip: For more information about the implicit grant flow and how the URL below is formed, see using OAth 2.0 for client-side web applications.
The following URL uses a client ID that was created in the Google Cloud Platform Console to request an access token and then redirect the user to an authorized URI where your app receives the token:
https://accounts.google.com/o/oauth2/v2/auth? response_type=token& client_id=[MY_CLIENT_ID].apps.googleusercontent.com& scope=https://www.googleapis.com/auth/cloud-platform& redirect_uri=[MY_REDIRECT_URI]
[MY_CLIENT_ID]is a Client ID from one of your credentials in the Cloud Platform Console.
[MY_REDIRECT_URI]is the corresponding Authorized redirect URIs from the same credential in the Cloud Platform Console. If no redirect URI is specified, you must specify a trusted URI, for example
https://www.google.com. The redirect URI defines where the HTTP response is sent. For production, you must specify your application's auth endpoint, which handles responses from the OAuth 2.0 server. For more information, see Using OAuth 2.0 for Web Server Applications.
When the application uses the URL to request authorization, the access token is returned in a response, for example:
https://www.google.com/#access_token=[MY_ACCESS_TOKEN]& token_type=Bearer& expires_in=3600
[MY_ACCESS_TOKEN] is the returned access token that you requested.
After you obtain an access token, you can use it to access the Admin API. For example, your application's auth endpoint can programmatically extract the access token from the response. See the following example for how to manually use your token in a cURL command.
HTTP request example using cURL
The following cURL command demonstrates how you can use your
access token to make an HTTP
POST request. This cURL command deploys
the resources defined in the
app.json configuration file to the
default service in the application of project
curl -X POST -T "app.json" -H "Content-Type: application/json" -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/services/default/versions