Skip to main content

Integrate Google OAuth with Langflow

Langflow integrates with Google OAuth for authenticating the Gmail loader, Google Drive loader, and Google Drive Search components.

Learn how to create an OAuth app in Google Cloud, obtain the necessary credentials and access tokens, and add them to Langflow’s Google components.

Create an OAuth Application in Google Cloud​

  1. Navigate to the Google Cloud Console.

  2. Click Select a project, and then click New Project to create a new project.

OAuth Client ID and Secret

  1. To enable APIs for the project, select APIs & Services, and then click Library. Enable the APIs you need for your project. For example, if your flow uses the Google Drive component, enable the Google Drive API.
  2. To navigate to the OAuth consent screen, click APIs & Services, and then click OAuth consent screen.
  3. Populate your OAuth consent screen with the application name, user support email, required scopes, and authorized domains.
  4. To create an OAuth Client ID, navigate to Clients, and then click Create Client.
  5. Choose Desktop app as the application type, and then name your client ID.
  6. Click Create. A Client ID and Client Secret are created. Download the credentials as a JSON file to your local machine and save it securely.

OAuth Client ID and Secret


Retrieve Access and Refresh Tokens​

With your OAuth application configured and your credentials JSON file created, follow these steps to authenticate the Langflow application.

  1. Create a new project in Langflow.
  2. Add a Google OAuth Token component to your flow.
  3. In the Credentials File field of the Google OAuth Token component, enter the path to your Credentials File, the JSON file containing the Client ID credentials you downloaded from Google in the previous steps.
  4. To authenticate your application, in the Google OAuth Token component, click Play. A new tab opens in the browser to authenticate your application using your Google Cloud account. You must authenticate the application with the same Google account that created the OAuth credentials.
info

If a new tab does not open automatically, check the Langflow Logs for the Google authentication URL. Open this URL in your browser to complete the authentication.

  1. After successful authentication, your Langflow application can now request and refresh tokens. These tokens enable Langflow to interact with Google services on your behalf and execute the requests you’ve specified.

Create a flow with Google Drive loader​

For a pre-built JSON file of a flow that uses the Google Drive loader component, download the Google Drive Document Translation Example Flow JSON to your local machine.

In this example, the Google Drive loader component loads a text file hosted on Google Drive, translates the text to Spanish, and returns it to a chat output.

  1. Download the Google Drive Document Translation Example Flow JSON to your local machine.
  2. To import the downloaded JSON to Langflow, click Options, and then select Import.
  3. In the Credentials File field of the Google OAuth Token component, enter the path to your Credentials File, the JSON file containing the Client ID credentials you downloaded from Google in the previous steps.
  4. In the Google Drive loader component, in the JSON String of the Service Account Token field, enter the JSON string containing the token returned in the output of the Google OAuth Token component.

The example flow includes a Parse data component to convert the data output of the Google OAuth Token component to the text input of the JSON Cleaner component.

  1. To allow the Langflow component to access the file in Google Drive, copy the Google Drive File ID from the document's URL.
info

The file ID is located between /d/ and /edit in a Google Drive document's URL. For example, in the URL https://drive.google.com/file/d/1a2b3c4D5E6F7gHI8J9klmnopQ/edit, the File ID is 1a2b3c4D5E6F7gHI8J9klmnopQ.

  1. In the Google Drive loader component, in the Document ID field, paste the document URL.
  2. Click the Chat output component, and then click Play. The chat output should display a translated document.

Hi, how can I help you?