2025-05-07 09:25:42 -07:00
|
|
|
# OAuth Sample
|
|
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
|
|
|
|
|
This sample tests and demos the OAuth support in ADK via two tools:
|
|
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 1. list_calendar_events
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
This is a customized tool that calls Google Calendar API to list calendar
|
|
|
|
|
events. It pass in the client id and client secrete to ADK and then get back
|
|
|
|
|
the access token from ADK. And then it uses the access token to call
|
|
|
|
|
calendar api.
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 2. get_calendar_events
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-11-03 13:33:18 -08:00
|
|
|
This is a google calendar tool that calls Google Calendar API to get the
|
2025-10-21 10:34:47 -07:00
|
|
|
details of a specific calendar. This tool is from the ADK built-in Google
|
|
|
|
|
Calendar ToolSet. Everything is wrapped and the tool user just needs to pass
|
|
|
|
|
in the client id and client secret.
|
2025-05-07 09:25:42 -07:00
|
|
|
|
|
|
|
|
## How to use
|
|
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 1. Follow
|
|
|
|
|
https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name.
|
|
|
|
|
to get your client id and client secret. Be sure to choose "web" as your
|
|
|
|
|
client type.
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 2. Configure your `.env` file to add two variables:
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* OAUTH_CLIENT_ID={your client id}
|
|
|
|
|
* OAUTH_CLIENT_SECRET={your client secret}
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
Note: don't create a separate `.env` file , instead put it to the same
|
|
|
|
|
`.env` file that stores your Vertex AI or Dev ML credentials
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 3. Follow
|
|
|
|
|
https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred
|
|
|
|
|
to add http://localhost/dev-ui/ to "Authorized redirect URIs".
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
Note: localhost here is just a hostname that you use to access the dev ui,
|
|
|
|
|
replace it with the actual hostname you use to access the dev ui.
|
2025-05-07 09:25:42 -07:00
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* 4. For 1st run, allow popup for localhost in Chrome.
|
2025-05-07 09:25:42 -07:00
|
|
|
|
|
|
|
|
## Sample prompt
|
|
|
|
|
|
2025-10-21 10:34:47 -07:00
|
|
|
* `List all my today's meeting from 7am to 7pm.`
|
|
|
|
|
* `Get the details of the first event.`
|