This page explains how to share an OAuth client with another application within
your organization.

## Overview

Sharing OAuth clients between projects means using a single, custom OAuth client
for multiple Identity-Aware Proxy (IAP)-protected applications
instead of creating a new OAuth client for each application. This approach
simplifies management, especially for organizations with many applications.

When configuring IAP, you can use one of two OAuth client
types:

- **Google-managed OAuth client**: IAP automatically uses
  this by default. This built-in option requires no manual client creation but
  has two key limitations:

  - Only allows access to users within your organization (internal users)

  - Displays Google Cloud branding on the consent screen instead of your
    organization's branding

- **Custom OAuth client**: You create and manage this yourself. This option:

  - Can be shared across multiple applications

  - Allows customization of branding on the consent screen

  - Supports access for external users (outside your organization)

When you create a custom OAuth client, you have the flexibility to use it with a
single application or share it across multiple applications. Sharing a custom
OAuth client provides several benefits:

- Reduces the administrative overhead of managing multiple clients

- Simplifies enabling IAP for team members who shouldn't
  have access to the Credentials page

- Facilitates programmatic (non-browser) access to applications protected by
  IAP

For information about creating OAuth clients, see
[Creating OAuth clients for IAP](https://docs.cloud.google.com/iap/docs/oauth-client-creation).
For details about Google-managed OAuth clients, see
[Customize an OAuth configuration to enable IAP](https://docs.cloud.google.com/iap/docs/custom-oauth-configuration.md.txt).

## Before you begin

Create a new OAuth client by completing the steps in
[OAuth client creation](https://docs.cloud.google.com/iap/docs/oauth-client-creation) or use an existing
OAuth client.

## Programmatic access

**Configure OAuth clients for programmatic access** to allow non-browser
applications to authenticate with your IAP-protected
resources. This enables scripts, automated jobs, and backend services to
securely access your protected applications without interactive user login.

You can apply these authentication settings at any level in your resource
hierarchy:
[organization](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy.md.txt#organizations),
[folder](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy.md.txt#folders), or
[project](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy.md.txt#projects).

For implementation steps, see the
[programmatic authentication guide](https://docs.cloud.google.com/iap/docs/authentication-howto.md.txt) and
[IAP settings management](https://docs.cloud.google.com/iap/docs/managing-access.md.txt)
documentation.

### gcloud

1. Prepare a settings file with your OAuth client IDs:

   ```bash
   cat << EOF > SETTINGS_FILENAME
     access_settings:
       oauth_settings:
         programmatic_clients: [clientId1, clientId2, ..]
   EOF
   ```
2. Apply settings using the
   [`gcloud iap settings set`](https://docs.cloud.google.com/sdk/gcloud/reference/iap/settings/set)
   command:

   ```bash
   gcloud iap settings set SETTINGS_FILENAME \
     [--organization=ORGANIZATION | --folder=FOLDER | --project=PROJECT] \
     [--resource-type=RESOURCE_TYPE] \
     [--service=SERVICE] \
     [--version=VERSION]
   ```

   Example commands:

   ```bash
   # Organization level
   gcloud iap settings set SETTINGS_FILENAME --organization=ORGANIZATION

   # Folder level
   gcloud iap settings set SETTINGS_FILENAME --folder=FOLDER

   # Project level (web resources)
   gcloud iap settings set SETTINGS_FILENAME \
     --project=PROJECT \
     --resource-type=iap_web

   # App Engine service in a project
   gcloud iap settings set SETTINGS_FILENAME \
     --project=PROJECT \
     --resource-type=app-engine \
     --service=SERVICE
   ```

   Where:
   - <var translate="no">SETTINGS_FILENAME</var>: The YAML file you prepared.

   - <var translate="no">ORGANIZATION</var>: The organization ID

   - <var translate="no">FOLDER</var>: The folder ID

   - <var translate="no">PROJECT</var>: The project ID

   - <var translate="no">RESOURCE_TYPE</var>: The IAP resource type
     (`app-engine`, `iap_web`, `compute`, `organization`, or `folder`)

   - <var translate="no">SERVICE</var>: The service name (optional for `compute` or
     `app-engine` resource types)

   - <var translate="no">VERSION</var>: The version name (not applicable for `compute`,
     optional for `app-engine`)

### API

1. Prepare a settings JSON file:

   ```bash
   cat << EOF > iap_settings.json
   {
     "access_settings": {
       "oauth_settings": {
         programmatic_clients: [clientId1, clientId2, ..]
       }
     }
   }
   EOF
   ```
2. Get the resource name:

   ```bash
   gcloud iap settings get \
     [--organization=ORGANIZATION | --folder=FOLDER | --project=PROJECT] \
     [--resource-type=RESOURCE_TYPE] \
     [--service=SERVICE] \
     [--version=VERSION]
   ```
3. Update the settings using the resource name:

   ```bash
   curl -X PATCH \
   -H "Authorization: Bearer $(gcloud auth print-access-token)" \
   -H "Accept: application/json" \
   -H "Content-Type: application/json" \
   -d @iap_settings.json \
   "https://iap.googleapis.com/v1/RESOURCE_NAME:iapSettings?updateMask=iapSettings.accessSettings.oauthSettings.programmaticClients"
   ```

   Where:
   - <var translate="no">ORGANIZATION</var>: The organization ID

   - <var translate="no">FOLDER</var>: The folder ID

   - <var translate="no">PROJECT</var>: The project ID

   - <var translate="no">RESOURCE_TYPE</var>: The IAP resource type
     (`app-engine`, `iap_web`, `compute`, `organization`, or `folder`)

   - <var translate="no">SERVICE</var>: The service name (optional for `compute` or
     `app-engine` resource types)

   - <var translate="no">VERSION</var>: The version name (not applicable for `compute`,
     optional for `app-engine`)

After configuration, sign in to the application using any one of the OAuth
client IDs that you configured. See
[Programmatic authentication](https://docs.cloud.google.com/iap/docs/authentication-howto.md.txt) for details.

## Browser access

To enable IAP to use your client ID and secret through the
Google Cloud console, complete the following instructions:

- [Configure OAuth Client for Compute Engine (Compute Engine)](https://docs.cloud.google.com/iap/docs/custom-oauth-configuration.md.txt#backend-service)

- [Configure OAuth Client for Google Kubernetes Engine (GKE)](https://docs.cloud.google.com/iap/docs/enabling-kubernetes-howto.md.txt)

- [Configure OAuth Client for App Engine](https://docs.cloud.google.com/iap/docs/custom-oauth-configuration.md.txt#app-engine)

- [Configure OAuth Client for Cloud Run](https://docs.cloud.google.com/iap/docs/custom-oauth-configuration.md.txt#cloud-run)

## Risks

While sharing a client between your applications is convenient, there are risks.
This section outlines potential risks when sharing clients and how to mitigate
them.

### Single point of failure

Using one OAuth client for many applications creates a single point of
dependency. If a client is deleted or modified incorrectly, every application
using that client is affected. Deleted OAuth clients can be restored within
30 days.

To manage this operational risk effectively:

- Implement proper access controls to prevent accidental changes or deletion

- Restrict access to OAuth clients using
  [`clientauthconfig.clients.*` permissions](https://docs.cloud.google.com/iap/docs/concepts-overview.md.txt)

- Use [Google Cloud Audit Logs](https://docs.cloud.google.com/logging/docs/audit.md.txt) to track
  administrative activities involving OAuth clients

This is primarily an operational risk rather than a security risk. With proper
access controls and monitoring in place, the convenience and management benefits
of shared OAuth clients typically outweigh this consideration.

### Client secret leaks

Sharing a client requires sharing your client secret with people and scripts.
This increases the risk of your client secret leaking. IAP
can't differentiate between tokens created from your application and tokens
created from a leaked client secret.

To mitigate this risk:

- Protect client secrets like passwords and never store them as plain text

- Implement secure credential management using
  [Secret Manager](https://docs.cloud.google.com/secret-manager/docs/overview.md.txt)

- Monitor access to your IAP resources with
  [Cloud Audit Logging](https://docs.cloud.google.com/logging/docs/audit.md.txt)

- A leaked client secret only impacts authentication, not authorization to
  access resources. If you suspect your secret was leaked, reset it
  immediately.

For programmatic access to IAP-protected resources, consider
using [service account JWT authentication](https://docs.cloud.google.com/iap/docs/authentication-howto.md.txt)
instead of sharing OAuth client secrets with individual users. This approach
provides better security isolation while maintaining the benefits of a shared
OAuth client for your applications.

### Permission scope considerations

When sharing OAuth clients, all applications use the same permission scopes. For
IAP, `openid` and `email` are the only required scopes. This consideration by itself isn't a significant risk, but it's important to
understand:

- OAuth is only used for **authentication** (verifying identity) in
  IAP; **authorization** (resource access) is handled
  separately through [IAM policies](https://docs.cloud.google.com/iap/docs/managing-access.md.txt)

- Even if authentication credentials are compromised, an attacker would still
  need appropriate IAM permissions to access protected
  resources

- Restricting the client to only the required `openid` and `email` scopes
  helps limit potential security impact