Use OAuth

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.

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.

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.

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.

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) to make the call. For more information about using ADC to call Google APIs with client libraries, see Authenticate using client libraries.

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.
  2. Install and initialize the gcloud CLI.
  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.

For more information, see the Local development environment section of the Provide credentials for Application Default Credentials 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

    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.

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.