This project provides a simple web-based user interface (built with NiceGUI) to help you create and manage OAuth Authorizations within a Google Cloud Project for use with Agentspace custom agents.
It leverages Google Cloud Application Default Credentials (ADC) to authenticate with the Google Cloud APIs (specifically the Discovery Engine API v1alpha for Authorizations and Cloud Resource Manager API for project number lookup).
- Create new Agentspace (Discovery Engine) Authorizations by providing OAuth client details.
- Delete existing Agentspace (Discovery Engine) Authorizations.
- Uses Application Default Credentials (ADC) for authentication.
- Provides a simple, intuitive web interface.
- Logs activity to a local file (
activity.log.YYYY-MM-DD).
- Python 3.12+: Ensure you have Python installed. May work with earlier versions of Python
- Google Cloud Project: You need an active Google Cloud Project.
- Application Default Credentials (ADC): The script authenticates using ADC. Make sure your environment is set up to provide these credentials. This typically involves:
- Running
gcloud auth application-default loginon your local machine. - Or, setting the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable pointing to a service account key file (less recommended for local development). - Or, running the script on a GCP resource (like GCE, GKE, Cloud Run, etc.) with an attached service account that has the necessary permissions.
- Running
- Required Permissions: The credentials used must have permissions to:
- Read project information (e.g.,
resourcemanager.projects.get). - Manage Discovery Engine Authorizations (e.g.,
discoveryengine.authorizations.create,discoveryengine.authorizations.delete). Theroles/discoveryengine.adminor a custom role with these specific permissions should suffice.
- Read project information (e.g.,
Clone the repository and install the required Python packages:
pip install -r requirements.txt # (Assuming you create a requirements.txt)
# OR manually install:
# pip install requests google-auth google-api-python-client python-dotenv nicegui(Note: A requirements.txt file is recommended for managing dependencies)
The script requires your Google Cloud Project ID. You can provide this in two ways:
-
Environment Variable: Set the
GOOGLE_CLOUD_PROJECTenvironment variable before running the script. -
.env file: Create a file named
.envin the same directory aswebui_as_authentication.pyand add the following line:GOOGLE_CLOUD_PROJECT=your-gcp-project-id
Replace
your-gcp-project-idwith your actual GCP project ID. The script usespython-dotenvto load this file automatically.
Once prerequisites are met and dependencies are installed, run the script:
python as_authentication_manager.pyThe web UI will start, typically accessible at http://localhost:8081. Open this URL in your web browser.
- Enter your GCP Project ID in the configuration section (this field might be pre-filled if set via
.envor environment variable). - Navigate between the "Create Authorization" and "Delete Authorization" tabs.
- Currently, the user must remember/track the authorization id(s) they have created, if they wish to delete them later. There is no GET or
listmethod(s) for Authorizations as of 21 May 2025. - Fill in the required details for the desired action and click the corresponding button.
- Status and results will be displayed in the status area below the buttons.
- Check
activity.login the script's directory for detailed logs of API calls and responses.