API calls to the zero-touch enrollment customer API need authorization. Requiring authorization protects your organization's data. To authorize calls to the zero-touch enrollment API, you need to complete the following tasks:
- Create a service account to call the APIs.
- Store the JSON key file to authorize the API calls.
- Enable the API to make it available to the service account.
- Link the service account to make API calls on behalf of your organization.
Use the instructions below to help you complete the tasks.
Step 1: create a service account
A service account, sometimes called a robot account, is a Google Account representing applications instead of users. Your app calls APIs on behalf of the service account, so users aren't directly involved. Because your app is using Google APIs, use the Google API Console to set up access.
Create an API Console project
It's good practice to create a new API Console project and service account for your app. This makes managing access, managing resources, and fixing lost keys easier in the future. Start by following the steps below to create a new project in Google API Console:
- Go to the API Console.
- From the projects list, select Create a project.
- Enter a name that describes your app and zero-touch enrollment.
- Specify a project ID or accept the default.
- Click Create.
To find out more, read the Google Cloud Platform document Manage projects in the console.
Add new service credentials
To add new credentials and a service account to your project, follow the steps below in your API Console.
- Open the Service accounts page. If prompted, select a project.
- Click Create Service Account, enter a name and description for the service account. You can use the default service account ID, or choose a different, unique one. When done click Create.
- The Service account permissions (optional) section that follows is not required. Click Continue.
- On the Grant users access to this service account screen, scroll down to the Create key section. Click Create key.
- In the side panel that appears, select the format for your key: JSON is recommended.
- Click Create. Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key. For information on how to store it securely, see Managing service account keys.
- Click Close on the Private key saved to your computer dialog, then click Done to return to the table of your service accounts.
Copy the email address of the service account and keep it handy. You need it later when you link the service account to your organization.
Step 2: store the JSON key file
API Console generates a new private key pair used to authenticate API calls made using your service account. The private key is in the JSON key file you download.
You should keep the key private, so don't include it in your app's source code. If you lose the key file, you need to generate a new pair of keys.
To learn more about storing the key file securely, read Best practices for securely using API keys.
Step 3: enable the API
Before your app can use the API, you need to enable it. Enabling an API associates it with the current API Console project and adds monitoring pages in your console.
To enable the API, follow the steps below in your API Console:
- Click APIs & Services > Library.
- Use the search field to find the Android Device Provisioning Partner API.
- Click Android Device Provisioning Partner API.
- Click Enable.
After a short delay, the API status changes to enabled. If you don't see Android Device Provisioning Partner API, check your organization is onboarded into zero-touch enrollment. Make sure you're using the same Google Account for zero-touch enrollment and Google API Console.
Step 4: link the service account
Linking the service account with your organization's zero-touch enrollment account authorizes the service account to make API calls on behalf of your organization. Fill out the link request form to link your service account.
If you can't find the email address of the service account you created, copy it from one of the following places:
- The Service account email from Service accounts page in the Google API Console.
client_emailproperty field in the JSON key file.
Once you receive email confirmation that your account is linked, your service account can then make calls to the customer API on behalf of your organization.
Try out the API
Use the API authorization scope
https://www.googleapis.com/auth/androidworkzerotouchemm in your app to request
an OAuth 2.0 access token.
A scope parameter controls the set of resources and operations that an access token permits calls to. Access tokens are valid only for the set of operations and resources described in the scope of the token request. The API covers all the methods and resources with the single zero-touch enrollment scope shown above.
To learn more about using Google API scopes, read Using OAuth 2.0 to Access Google APIs.