Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

API to add authorized Javascript origin and redirect URI to OAuth2 client id

I am looking for an API to add authorized Javascript origins and redirect URIs to an existing OAuth2 client id (Web application). So basically an API for the configuration settings in the GCP console under API & Services -> Credentials -> OAuth2 client ids.

Does someone know of such an API?

0 1 1,327
1 REPLY 1

Hi @RiyaAgarwal,

There isn't a direct API to modify the authorized JavaScript origins and redirect URIs of an existing OAuth 2.0 client ID in the Google Cloud Console via the same interface you see. The Google Cloud Console's UI is not directly exposed as a programmatic API.

Instead, you need to use the Google Cloud Resource Manager API and the Admin SDK. This involves creating and managing the OAuth 2.0 client ID as a resource and updating its configuration.

Here's a breakdown of the process and the relevant APIs:

  • Identify the OAuth 2.0 client ID: You'll need the project_id and the client_id itself. You can find these information in the Google Cloud Console under API & Services -> Credentials.
  • Use the Google Cloud Resource Manager API: This API allows you to manage Google Cloud resources, but it doesn't directly handle the specific details of the OAuth 2.0 client (like redirect URIs). You might use this to get the project's information if you need to programmatically discover the client ID, but it won't directly modify the client settings.
  • Use the Admin SDK (if applicable): If your use case involves managing OAuth 2.0 client IDs for Google Workspace accounts (managing APIs for your organization), the Google Workspace Admin SDK may offer more direct control. However, this isn't typically needed for individual projects or personal Google Cloud accounts. The Admin SDK is a more powerful tool that requires higher-level privileges.
  • Consider using the Google Cloud Client Libraries: These libraries wrap the underlying APIs, simplifying the process. You will likely need the Google Cloud Client Library for your preferred programming language (Python, Node.js, etc.). However, even with the client libraries, you won't find a single function to directly update the JavaScript origins and redirect URIs. You'll have to create or update the client via the Admin SDK or the Resource Manager API depending on your needs.

In summary, while a direct API for modifying existing OAuth 2.0 client ID configurations is currently unavailable, alternative strategies exist to manage access and configuration. The optimal solution will depend on your specific needs, technical expertise, and security requirements. Prioritize security and carefully consider the effort involved before implementing a custom solution.

I hope the above information is helpful.