DEV Community

Marcos Manuel Ortega
Marcos Manuel Ortega

Posted on

Automatically add your Cloud Shell URL to OAuth client authorized URIs

TL;DR

Simple repo to automatically check your Cloud Shell env URL is included in your OAuth client authorized URIs, and if not, show instructions to include it, plus a test sample app.

Use case: Developing in Cloud Shell + OAuth client

If you, like me, love developing within Cloud Shell (specially if you're on the go with a tablet), you know the drill: when you preview your webapp, you're using your Cloud Shell env URL (with a port number prefix), which is not static: it can change in the future, and every user has a different Cloud Shell env and thus URL.

If you're using a OAuth client, for example for using Sign in with Google, you need to also include your local URL as an authorized JS origins and redirect URL, along your prod URLs.

Therefore, this means whenever your Cloud Shell env URL changes, or for each user, you need to check and update said URLs in your OAuth client config.

Pain point: no API to automate

For long, I wanted to automate this with a script that checks and updates your OAuth client config. Unfortunately, Google Auth Platform (included in the Google Cloud Console) doesn't offer an API, CLI or client library to update your OAuth client config - I've heard due to security reasons, but alas.

Although that means you can't automate the full flow, this tool performs the check to a downloaded OAuth client and shows you instructions and links to update the OAuth client config.

Usage

The tool can be run manually, or be run automatically at Cloud Shell startup. Instructions included in the Readme.

It also includes a test hello world sample webapp with a "Sign in with Google" button for testing the tool and your Oauth client config.

Comments, issues, improvements? Please, just ping me!

OSS GitHub repo

Top comments (0)