Roads Selection API uses the Roads Selection API as a core component that
provides road data to BigQuery and Pub/Sub.

Roads Selection 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 Roads Selection API call
in your **development** environment. For more information about using OAuth
in a **production** environment, see
[Authentication at Google](https://cloud.google.com/docs/authentication).

## Before you begin

Before you start using the Roads Selection API, you must have a project with a
billing account and the Roads Selection API enabled. For more information, see
[Set up in
Cloud Console](https://developers.google.com/maps/documentation/roads-management-insights/cloud-setup).

## 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 must have a service account, which is an account that belongs
to your application instead of to 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 the Roads Selection API as part of an Android or
iOS mobile app. For more information about using OAuth with the
Roads Selection 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 Roads Selection API, the OAuth token must have the
`https://www.googleapis.com/auth/cloud-platform` scope.

## Example: Try REST API calls in your local development environment

If you want to try the Roads Selection API using an OAuth token, but don't
have an environment set up to generate tokens, follow the procedure in this
section to make the request.

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 isn't intended for use in a production environment. Use this procedure for a development or testing environment only.

### 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/roads-management-insights/cloud-setup).
2. [Install and initialize the gcloud CLI](https://cloud.google.com/sdk/docs/install?utm_source=Docs_InstallGcloud&utm_content=Docs_roads).
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/roads-management-insights/cloud-setup).

Make a call to the Roads Selection API by using an OAuth token:

```
curl -X GET \
-H 'X-Goog-User-Project: PROJECT_NUMBER' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
https://roads.googleapis.com/selection/v1/projects/PROJECT_NUMBER/selectedRoutes/SELECTED_ROUTE_ID
```

### Troubleshooting

If your request returns an error message about end-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).