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​
-
Navigate to the Google Cloud Console.
-
Click Select a project, and then click New Project to create a new project.
- 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.
- To navigate to the OAuth consent screen, click APIs & Services, and then click OAuth consent screen.
- Populate your OAuth consent screen with the application name, user support email, required scopes, and authorized domains.
- To create an OAuth Client ID, navigate to Clients, and then click Create Client.
- Choose Desktop app as the application type, and then name your client ID.
- 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.
Retrieve Access and Refresh Tokens​
With your OAuth application configured and your credentials JSON file created, follow these steps to authenticate the Langflow application.
- Create a new project in Langflow.
- Add a Google OAuth Token component to your flow.
- 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.
- 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.
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.
- 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.
- Download the Google Drive Document Translation Example Flow JSON to your local machine.
- To import the downloaded JSON to Langflow, click Options, and then select Import.
- 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.
- 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.
- To allow the Langflow component to access the file in Google Drive, copy the Google Drive File ID from the document's URL.
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
.
- In the Google Drive loader component, in the Document ID field, paste the document URL.
- Click the Chat output component, and then click Play. The chat output should display a translated document.