Authorize requests

When your application requests private user data, the request must be authorized by an
authenticated user who has access to that data. This is called user-centric OAuth 2.0 flow.
If your application doesn't need to access user data, then you should use a server-centric
OAuth 2.0 flow based on a service account. For more information about these two OAuth flows and
authentication in general, see Cloud Storage Authentication.
This page describes the different type of credentials you can create and use with Cloud Storage for
both user-centric
flows and
server-centric OAuth 2.0 flows.

Identifying your application

Any request your application sends to the Cloud Storage JSON API that requires authorization
needs to identify your application to Google. There are two ways to identify your application:
using an OAuth 2.0 token (which also authorizes the request)
and/or using the application's API key. Here's how to determine which of
those options to use:

If the request requires authorization (such as a request for an individual's private data),
then the application must provide an OAuth 2.0 token with the request. The application may also
provide the API key, but it doesn't have to.

If the request doesn't require authorization (such as a request for public data), then no
identification is required; however, the application may still provide the API key, an OAuth
2.0 token, or both.

About authorization protocols

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

Authorizing requests with OAuth 2.0

Requests to the Cloud Storage JSON API for non-public user data must be authorized by an authenticated user.

The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

When you create your application, you register it using the Google Cloud Platform Console. Google then provides information you'll need later, such as a client ID and a
client secret.

Activate the Cloud Storage JSON API in the Google Cloud Platform Console. (If the API isn't listed in the GCP Console, then skip this step.)

When your application needs access to user data, it asks Google for a particular scope of access.

Google displays a consent screen to the user, asking them to authorize your application to request some of their data.

If the user approves, then Google gives your application a short-lived access token.

If Google determines that your request and the token are valid, it returns the requested data.

Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.

To request access using OAuth 2.0, your application needs the scope information, as well as
information that Google supplies when you register your application (such as the client ID and the
client secret).

Acquiring and using an API key

Requests to the Cloud Storage JSON API for public data may be accompanied by an identifier, which can
be an API key or an
access token.

This API supports two types of credentials.
Create whichever credentials are appropriate for your project:

OAuth 2.0: Whenever your application requests private user
data, it must send an OAuth 2.0 token along with the request. Your
application first sends a client ID and, possibly, a client secret to
obtain a token. You can generate OAuth 2.0 credentials for web
applications, service accounts, or installed applications.

The API supports several types of restrictions on API keys. If the API key that you
need doesn't already exist, then create an API key in the Console by
clicking Create credentials > API key. You can restrict the key before using it
in production by clicking Restrict key and selecting one of the
Restrictions.