Map Management API supports the use of OAuth 2.0 for authentication.
Google supports common OAuth 2.0 scenarios, such as those for a web server.

This document describes how to pass an OAuth token to the Map Management API call in your
**development** environment. For instructions on using OAuth in a
**production** environment, see
[Authentication at Google](https://cloud.google.com/docs/authentication).

## Before you begin

Before you start using Map Management API, you need a
project with a billing account and Map Management API enabled. For more
information, see [Set up in Cloud Console](https://developers.google.com/maps/documentation/mapmanagement/cloud-setup.md.txt).

## About OAuth

You can create and manage access tokens with OAuth in several ways
depending on your deployment environment.

For example, the Google OAuth 2.0 system supports server-to-server
interactions, such as those between your application and a Google service. For this scenario, you need a service account. This account belongs to your
application instead of an individual user. Your application calls Google APIs
on behalf of the service account because users aren't directly involved.
For more information about authentication methods, see
[Authentication at Google](https://cloud.google.com/docs/authentication).

Alternatively, you can use Map Management API as part of an Android or iOS
mobile app. For more information about using OAuth with Map Management API,
including information about managing access tokens for different deployment
environments, see
[Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2.md.txt).

## About OAuth scopes

To use OAuth with the Map Management API, the OAuth token must have the
scope `https://www.googleapis.com/auth/cloud-platform`.

## Try REST API calls in your local development environment

If you want to try the Map Management API using an OAuth token, but don't
have an environment set up to generate tokens, you can use the procedure in
this section to make the call.

This example describes how to use the OAuth token provided by
[Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials)
to make the call. For more information about using ADC to call Google APIs
with client libraries, see
[Authenticate using client libraries](https://cloud.google.com/docs/authentication/client-libraries).

> [!NOTE]
> **Note**: The following procedure to make a REST call is for development and testing environments only. Don't use it in production.

### Prerequisites

Before you can make a REST request using ADC, use the Google Cloud CLI
to provide credentials to ADC:

1. If you haven't already, create a project and enable billing by following the steps in [Set up in Cloud Console](https://developers.google.com/maps/documentation/mapmanagement/cloud-setup.md.txt).
2. [Install and initialize the gcloud CLI](https://cloud.google.com/sdk/docs/install?utm_source=Docs_InstallGcloud&utm_content=Docs_mapmanagement).
3. To create your credential file, run the `gcloud` command on
   your local machine:

   ```
   gcloud auth application-default login
   ```
4. When prompted, sign in. After you sign in, your credentials are stored in the [local credential file used by ADC](https://cloud.google.com/docs/authentication/application-default-credentials#personal).

For more information, see the
[Local development environment](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev)
section of the
[Provide credentials for Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc)
documentation.

### Make a REST request

In this example, you pass two request headers:

- Pass the OAuth token in the `Authorization` header by using
  the following command to generate the token:

  [`gcloud auth application-default print-access-token`](https://cloud.google.com/sdk/gcloud/reference/auth/application-default/print-access-token)

  The returned token has a scope of
  `https://www.googleapis.com/auth/cloud-platform`.
- Pass the ID or name of your Google Cloud project that has billing enabled in the `X-Goog-User-Project` header. For more information, see [Set up in Cloud Console](https://developers.google.com/maps/documentation/mapmanagement/cloud-setup.md.txt).

Make a call to the Map Management API by using an OAuth token:

```
curl -X GET \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "X-Goog-User-Project: PROJECT_ID" \
https://mapmanagement.googleapis.com/v2beta/projects/PROJECT_NUMBER_OR_ID/mapConfigs/
```

### Troubleshooting

If your request returns an error message about user credentials not being
supported by this API, see
[User credentials not working](https://cloud.google.com/docs/authentication/provide-credentials-adc#user-creds-client-based).