You can create, view, update, and delete OAuth clients and client credentials to
integrate your OAuth-based applications with Google Cloud.
Registering an OAuth client lets federated workforce users sign in to your
applications and access Google Cloud resources.

<br />

> [!IMPORTANT]
> **Important:** OAuth application integration works only with Identity-Aware Proxy and Looker.

<br />

> [!NOTE]
> **Note:** These steps and the `projects.locations.oauthClients` API are only for [Workforce Identity Federation](https://docs.cloud.google.com/iam/docs/workforce-identity-federation.md.txt). To create and manage standard OAuth 2.0 client IDs for Google Cloud users or services, go to the Google Cloud console, then go to [**APIs \& Services \>Credentials**](https://console.cloud.google.com/apis/credentials).

At a high level, to integrate an OAuth-based application, you do the following:

1. [Create an OAuth client](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#create).
2. [Create an OAuth client credential](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#create-credential).
3. In the OAuth client credential, obtain the client secret. To learn about risks associated with storing and accessing the client secret and strategies that can help mitigate them, see [OAuth client and credential security risks and mitigations](https://docs.cloud.google.com/iam/docs/workforce-oauth-app.md.txt#security).

After you complete these steps, the OAuth-based application can access
Google Cloud products and data. For Looker integrations, you can
redirect users to the authorization endpoint
(`https://auth.cloud.google/authorize`) to obtain an authorization code and
then use the registered OAuth client credentials to exchange authorization codes
or refresh tokens with the
[Cloud OAuth API](https://docs.cloud.google.com/iam/docs/cloud-oauth-api-overview.md.txt).

## Before you begin

1. You must have a Google Cloud organization set up.

2.


   [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

   After installation,
   [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

   ```bash
   gcloud init
   ```


   If you're using an external identity provider (IdP), you must first
   [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).

   > [!NOTE]
   > **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.

   <br />

3. You must have set up a workforce identity pool and provider in the
   organization in which you will register the OAuth application. Learn
   how to set up workforce identity federation for [Microsoft Entra ID](https://docs.cloud.google.com/iam/docs/workforce-sign-in-microsoft-entra-id.md.txt),
   [Okta](https://docs.cloud.google.com/iam/docs/workforce-sign-in-okta.md.txt), and [other OIDC and SAML 2.0 providers](https://docs.cloud.google.com/iam/docs/configuring-workforce-identity-federation.md.txt).

## Required roles


To get the permissions that
you need to register an OAuth application and manage its credentials for your organization,

ask your administrator to grant you the
[IAM OAuth Client Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.oauthClientAdmin) (`roles/iam.oauthClientAdmin`) IAM role on the project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


This predefined role contains

the permissions required to register an OAuth application and manage its credentials for your organization. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to register an OAuth application and manage its credentials for your organization:

- `iam.oauthClients.create`
- `iam.oauthClients.delete`
- `iam.oauthClients.get`
- `iam.oauthClients.list`
- `iam.oauthClients.update`
- `iam.oauthClientCredentials.create`
- `iam.oauthClientCredentials.delete`
- `iam.oauthClientCredentials.get`
- `iam.oauthClientCredentials.list`
- `iam.oauthClientCredentials.update`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

## Manage OAuth clients

This section shows you how to manage OAuth clients.

### Create an OAuth client

To create an OAuth client, do the following:

### gcloud

```bash
gcloud iam oauth-clients create APP_OAUTH_CLIENT_ID \
    --project=PROJECT_ID \
    --location=global \
    --client-type="CONFIDENTIAL_CLIENT" \
    --display-name="My OAuth application" \
    --description="An application registration for MyApp" \
    --allowed-scopes="https://www.googleapis.com/auth/cloud-platform" \
    --allowed-redirect-uris="REDIRECT_URI" \
    --allowed-grant-types="authorization_code_grant"
```

Replace the following:

- `APP_OAUTH_CLIENT_ID`: a client ID to represent this OAuth client.
- `PROJECT_ID`: the ID of the project where you created your workforce identity pool and provider. The project must be created in the organization where your workforce pool and provider were created.
- `REDIRECT_URI`: the redirect URI for the OAuth application---for example, `https://myapp.com/signin-callback`.

### REST

```bash
curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  -d "{ \
        'allowedGrantTypes': ['AUTHORIZATION_CODE_GRANT'], \
        'allowedRedirectUris': ['REDIRECT_URI'], \
        'allowedScopes': ['https://www.googleapis.com/auth/cloud-platform'], \
        'clientType': 'CONFIDENTIAL_CLIENT', \
        'description': 'My OAuth client description', \
        'disabled': false, \
        'displayName': 'My OAuth client'}" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients\?oauthClientId\=APP_OAUTH_CLIENT_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you created your workforce identity pool and provider. The project must be created in the organization where your workforce pool and provider were created.
- `REDIRECT_URI`: the redirect URI for the OAuth application---for example, `https://myapp.com/signin-callback`.
- `APP_OAUTH_CLIENT_ID`: a client ID to represent this OAuth client.

After you register the application, you [create the OAuth client credential](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#create-credential)
and obtain the secret that the OAuth application uses to access
Google Cloud.

### List OAuth clients

To list registered OAuth clients, run the following command:

### gcloud

```bash
gcloud iam oauth-clients list \
    --project=PROJECT_ID \
    --location=global
```

### REST

```bash
curl \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients
```

Replace `PROJECT_ID` with the ID of the project where
your OAuth applications are registered.

### Describe an OAuth client

To describe an OAuth client, run the following command:

### gcloud

```bash
gcloud iam oauth-clients describe APP_OAUTH_CLIENT_ID \
    --project PROJECT_ID \
    --location global
```

Replace the following:

- `APP_OAUTH_CLIENT_ID`: the ID of the OAuth client that you want to describe
- `PROJECT_ID`: the ID of the project where you registered your OAuth application

### REST

```bash
curl \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the ID of the OAuth client that you want to describe

### Update an OAuth client

To update an OAuth client, run the following command.

### gcloud

```bash
gcloud iam oauth-clients update APP_OAUTH_CLIENT_ID \
    --project=PROJECT_ID \
    --location=global \
    --allowed-redirect-uris="REDIRECT_URI"
```

Replace the following:

- `APP_OAUTH_CLIENT_ID`: the OAuth client ID for the OAuth client that you want to update
- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `REDIRECT_URI`: the redirect URI for the OAuth application

To update other fields, use flags listed in [`gcloud iam oauth-clients update`](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#create).

### REST

```bash
curl -d'{"allowedRedirectUris":"REDIRECT_URI"}' \
  -H "Content-Type: application/json" -X PATCH \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID?update_mask=allowed_redirect_uris
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID for the OAuth client that you want to update
- `REDIRECT_URI`: the redirect URI for the OAuth client

To update other fields, set `update_mask` to the field names listed in
[`gcloud iam oauth-clients update`](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#create).

### Delete an OAuth client

To delete an OAuth client, run the following command:

### gcloud

```bash
gcloud iam oauth-clients delete APP_OAUTH_CLIENT_ID \
    --project PROJECT_ID \
    --location global
```

Replace the following:

- `APP_OAUTH_CLIENT_ID`: the OAuth client ID to delete
- `PROJECT_ID`: the ID of the project where you registered your OAuth application

### REST

```bash
curl -X DELETE \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID to delete

## Manage OAuth client credentials

This section shows you how to manage OAuth client credentials for the
OAuth client.

### Create an OAuth client credential

To create an OAuth client credential, run the following
command:

### gcloud

```bash
gcloud iam oauth-clients credentials create APP_OAUTH_CLIENT_CREDENTIAL_ID \
    --oauth-client=APP_OAUTH_CLIENT_ID \
    --display-name='My OAuth client credential' \
    --location='global'
```

Replace the following:

- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: an ID that represents this client credential
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID you can obtain by [describing](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#describe) the registered OAuth client application

### REST

```bash
curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  -d "{'disabled': false, 'displayName': 'My OAuth client credential'}" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials\?oauthClientCredentialId=APP_OAUTH_CLIENT_CREDENTIAL_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID you can obtain by [describing](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#describe) the registered OAuth client application
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: an ID that represents this client credential

### List OAuth client credentials

To list OAuth client credentials, run the following command:

### gcloud

```bash
gcloud iam oauth-clients credentials list \
    --oauth-client=APP_OAUTH_CLIENT_ID \
    --project=PROJECT_ID \
    --location=global
```

Replace the following:

- `APP_OAUTH_CLIENT_ID`: the OAuth client ID for which to list credentials
- `PROJECT_ID`: the ID of the project where you registered your OAuth application

### REST

```bash
curl \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/$PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID for which to list credentials

### Describe an OAuth client credential

To describe an OAuth client credential, run the following command. You can
obtain the client secret by inspecting the output.

### gcloud

```bash
gcloud iam oauth-clients credentials describe APP_OAUTH_CLIENT_CREDENTIAL_ID \
    --oauth-client=APP_OAUTH_CLIENT_ID \
    --location='global'
```

Replace the following:

- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the redirect URI for the OAuth client
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID you can obtain by [describing](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#describe) the client application registration

### REST

```bash
curl \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials/APP_OAUTH_CLIENT_CREDENTIAL_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the redirect URI for the OAuth client
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID you can obtain by [describing](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#describe) the client application registration

In the output, `clientSecret` is the client secret. This is the secret that the
OAuth application uses to access Google Cloud.

> [!WARNING]
> **Warning:** The client secret must be stored securely. If the client secret is leaked, you must delete and re-create the client credential. To learn more, see [OAuth client and credential security risks and mitigations](https://docs.cloud.google.com/iam/docs/workforce-oauth-app.md.txt#security).

### Update an OAuth client credential

To update an OAuth client credential, run the following
command:

### gcloud

```bash
gcloud iam oauth-clients credentials update APP_OAUTH_CLIENT_CREDENTIAL_ID \
    --client-id=APP_OAUTH_CLIENT_ID \
    --display-name="My new credential name" \
    --location=global
```

### REST

```bash
curl -d'{"displayName":"My new credential name"}' -X PATCH \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials/APP_OAUTH_CLIENT_CREDENTIAL_ID?update_mask=display_name
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the redirect URI for the OAuth client
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID that you can obtain by [describing](https://docs.cloud.google.com/iam/docs/workforce-manage-oauth-app.md.txt#describe) the client application registration

### Disable an OAuth client credential

Before you can delete an OAuth client credential, you must disable it. To
disable the OAuth client credential, run the following command:

### gcloud

```bash
gcloud iam oauth-clients credentials update APP_OAUTH_CLIENT_CREDENTIAL_ID \
    --oauth-client=APP_OAUTH_CLIENT_ID \
    --disabled \
    --project=PROJECT_ID \
    --location=global
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the client credential ID to disable

### REST

```bash
curl -d'{"disabled":"true"}' \
  -H "Content-Type: application/json" -X PATCH \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials/APP_OAUTH_CLIENT_CREDENTIAL_ID?update_mask=disabled
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the OAuth client ID
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the client credential ID to disable

### Delete an OAuth client credential

To delete an OAuth client credential, run the following command:

### gcloud

```bash
gcloud iam oauth-clients credentials delete APP_OAUTH_CLIENT_CREDENTIAL_ID \
    --project=PROJECT_ID \
    --oauth-client=APP_OAUTH_CLIENT_ID \
    --location=global
```

Replace the following:

- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the OAuth client ID
- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the client credential ID

### REST

```bash
curl -X DELETE \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -H "X-Goog-User-Project: PROJECT_ID" \
  https://iam.googleapis.com/v1/projects/PROJECT_ID/locations/global/oauthClients/APP_OAUTH_CLIENT_ID/credentials/APP_OAUTH_CLIENT_CREDENTIAL_ID
```

Replace the following:

- `PROJECT_ID`: the ID of the project where you registered your OAuth application
- `APP_OAUTH_CLIENT_ID`: the client credential ID
- `APP_OAUTH_CLIENT_CREDENTIAL_ID`: the OAuth client ID

## What's next

- [Exchange tokens with the Cloud OAuth API](https://docs.cloud.google.com/iam/docs/cloud-oauth-exchange-tokens.md.txt)
- [Cloud OAuth API overview](https://docs.cloud.google.com/iam/docs/cloud-oauth-api-overview.md.txt)
- [Identity-Aware Proxy with workforce identity federation](https://docs.cloud.google.com/iap/docs/use-workforce-identity-federation.md.txt)