Skip to content

dataConnector Support #16837

@JoshLuxton

Description

@JoshLuxton

Determine this is the right repository

  • I determined this is the correct repository in which to report this feature request.

Summary of the feature request

Interested in Python package support for data connector endpoints:

https://docs.cloud.google.com/generative-ai-app-builder/docs/reference/rest/v1alpha/projects.locations.collections.dataConnector

Need this to programmatically replicate auth necessary for Gemini enterprise/vertex ai federated third party data connectors.

Desired code experience

> from google.cloud import discoveryengine_v1alpha
> 
> def manage_per_user_oauth_tokens(
>     project_id: str, 
>     location: str, 
>     collection_id: str,
>     end_user_id: str,
>     oauth_authorization_code: str = None
> ):
>     # Initialize the v1alpha Data Connector client
>     client = discoveryengine_v1alpha.DataConnectorServiceClient()
> 
>     # The singleton data connector resource name
>     # Format: projects/{project}/locations/{location}/collections/{collection}/dataConnector
>     connector_name = client.data_connector_path(
>         project=project_id,
>         location=location,
>         collection=collection_id
>     )
> 
>     # ==========================================
>     # 1. Acquire and Store Refresh Token
>     # ==========================================
>     # Typically called right after the user successfully completes 
>     # the OAuth consent screen on the third-party app and redirects back to your server.
>     if oauth_authorization_code:
>         print(f"Storing refresh token for user {end_user_id}...")
>         try:
>             store_request = discoveryengine_v1alpha.AcquireAndStoreRefreshTokenRequest(
>                 name=connector_name,
>                 # The identifier of the user in your application/EUC context
>                 # The exact attribute name may vary slightly based on proto definition updates
>                 user_identifier=end_user_id, 
>                 authorization_code=oauth_authorization_code
>             )
>             
>             store_response = client.acquire_and_store_refresh_token(request=store_request)
>             print("Refresh token successfully acquired and stored.")
>             
>         except Exception as e:
>             print(f"Failed to store refresh token: {e}")
> 
>     # ==========================================
>     # 2. Acquire Access Token
>     # ==========================================
>     # Called whenever your application or the Agent needs to act on behalf 
>     # of this specific user in the third-party system.
>     print(f"\nRetrieving access token for user {end_user_id}...")
>     try:
>         token_request = discoveryengine_v1alpha.AcquireAccessTokenRequest(
>             name=connector_name,
>             # Pass the same user identifier so the service knows which refresh token to use
>             user_identifier=end_user_id
>         )
>         
>         token_response = client.acquire_access_token(request=token_request)
>         
>         # Access the token directly from the response
>         access_token = token_response.access_token
>         print(f"Access Token retrieved successfully! (Length: {len(access_token)})")
>         
>         # Use this token to make authenticated API requests to the 3rd party service
>         return access_token
> 
>     except Exception as e:
>         print(f"Failed to acquire access token. Does the user have a stored refresh token? Error: {e}")
>         return None

Example usage:

user_access_token = manage_per_user_oauth_tokens(
project_id="my-gcp-project",
location="global",
collection_id="default_collection",
end_user_id="user@mycompany.com",
oauth_authorization_code="4/0AfgeXvv..." # Only pass this during the initial OAuth callback
#)

Expected results

No response

API client name and version

No response

Use case

_e.g. This feature would be useful in a scenario where I need to auth for users leveraging third party data connectors

Additional context

e.g. This feature would help improve the performance of my application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions