Skip to content

Commit 5cf738f

Browse files
feat: wire GoogleAuth with DB-backed token storage for per-user OAuth
- GoogleAuth instance shared across Gmail + Calendar toolkits - store_token_in_db=True enables DB-backed credential storage - OAuth callback router mounted at /google/oauth/callback - Tokens stored per user_id in agno_auth_tokens table Requires: agno-agi/agno#7404 (per-run toolkit cloning)
1 parent 6516b8e commit 5cf738f

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

app/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from db import get_postgres_db
1919
from pal.agents import compiler, linter, navigator, researcher, syncer
2020
from pal.agents.settings import pal_knowledge, pal_learnings
21-
from pal.config import GIT_SYNC_ENABLED, PAL_REPO_URL, SLACK_SIGNING_SECRET, SLACK_TOKEN
21+
from pal.config import GIT_SYNC_ENABLED, GOOGLE_INTEGRATION_ENABLED, PAL_REPO_URL, SLACK_SIGNING_SECRET, SLACK_TOKEN
2222
from pal.team import pal
2323

2424
# ---------------------------------------------------------------------------
@@ -78,6 +78,13 @@ async def lifespan(app): # type: ignore[no-untyped-def]
7878
app = agent_os.get_app()
7979
app.include_router(create_router(agent_os.settings))
8080

81+
# Google OAuth callback — exchanges auth code for tokens, stores in DB
82+
if GOOGLE_INTEGRATION_ENABLED:
83+
from pal.tools.build import google_auth_instance
84+
85+
if google_auth_instance:
86+
app.include_router(google_auth_instance.get_oauth_router(db=get_postgres_db()))
87+
8188

8289
# ---------------------------------------------------------------------------
8390
# Startup helpers

pal/tools/build.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
GOOGLE_INTEGRATION_ENABLED,
1313
PAL_CONTEXT_DIR,
1414
)
15+
16+
# Shared GoogleAuth coordinator — one instance for tools + OAuth callback router
17+
google_auth_instance = None
18+
if GOOGLE_INTEGRATION_ENABLED:
19+
from agno.tools.google.auth import GoogleAuth
20+
21+
google_auth_instance = GoogleAuth()
1522
from pal.tools.git import create_sync_tools
1623
from pal.tools.ingest import create_ingest_tools
1724
from pal.tools.knowledge import create_update_knowledge
@@ -38,12 +45,13 @@ def build_navigator_tools(knowledge: Knowledge) -> list:
3845
_, _, read_manifest, _ = create_ingest_tools(RAW_DIR)
3946
tools.append(read_manifest)
4047

41-
if GOOGLE_INTEGRATION_ENABLED:
48+
if GOOGLE_INTEGRATION_ENABLED and google_auth_instance:
4249
from agno.tools.google.calendar import GoogleCalendarTools
4350
from agno.tools.google.gmail import GmailTools
4451

45-
tools.append(GmailTools(send_email=False, send_email_reply=False, list_labels=True))
46-
tools.append(GoogleCalendarTools(allow_update=True))
52+
tools.append(google_auth_instance)
53+
tools.append(GmailTools(google_auth=google_auth_instance, store_token_in_db=True, send_email=False, send_email_reply=False, list_labels=True))
54+
tools.append(GoogleCalendarTools(google_auth=google_auth_instance, store_token_in_db=True, allow_update=True))
4755

4856
return tools
4957

0 commit comments

Comments
 (0)