feat: add per-user Gmail OAuth send flow#382
Open
decofe wants to merge 2 commits into
Open
Conversation
Cloudflare Workers docs preview |
653e92a to
25996ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-user Gmail OAuth send support for Slack users:
/ai-email-connect,/ai-email-status,/ai-email-disconnectephemeral Slack commandsS256) to prevent leaked OAuth URL account bindingsend_emailtool that accepts onlytrigger_message_ts,to,cc,bcc,subject, andbodygmail_oauth_send_auditSLACKBOT_EPHEMERAL_API_KEYsplit for/api/slack/ephemeralApproved Plan
Approved in Slack thread: https://slack.com/archives/C0A87C21805/p1780471107585029
Follow-up review fixes included: exact trigger-message lookup instead of latest-thread-user lookup, PKCE,
openid emailscope for connected-account status, encrypted recipients/subject, revoke failure isolation, expanded guardrail tests, pairing-token rate limiting, rate-limit pruning, confirmation-only tool wording, and optional narrower ephemeral-posting key.Security Guardrails Checklist
user_idfrom the exact persisted triggering Slack message row, not message text or latest thread message.(slack_team_id, slack_user_id).code_challenge_method=S256) with verifier recomputed from signed state/button-click material.from/on_behalf_of/as_user.send_emailtool only stages a confirmation; Gmail send happens only after the user clicks Send.openid emailfor connected-account display.invalid_grantmarks the connection invalid and prompts reconnect behavior.access_type=offline,prompt=consent, configured redirect URI, and no open redirect./ai-email-statusdistinguishes not-connected, connected-as-email, and connection-invalid states.Infra Reuse Summary
DATABASE_URL; new tables only.GMAIL_OAUTH_TOKEN_ENCRYPTION_KEYandGMAIL_OAUTH_TOKEN_KEY_VERSION.gmail_oauth_send_audit.SLACKBOT_EPHEMERAL_API_KEY; falls back to existing Slackbot key when unset for rollout compatibility.No new managed service, database, queue, secret manager, or SaaS was introduced.
Test Results
uv run pytest tests/test_gmail_oauth.py- 9 passeduv run ruff check api tests/test_gmail_oauth.py- passedbun run check:types- passedbun test src/index.test.ts src/gmail-oauth.test.ts- 5 passedManual QA
GMAIL_OAUTH_CLIENT_ID,GMAIL_OAUTH_CLIENT_SECRET,GMAIL_OAUTH_REDIRECT_URI,GMAIL_OAUTH_STATE_SIGNING_KEY,GMAIL_OAUTH_TOKEN_ENCRYPTION_KEY, andGMAIL_OAUTH_TOKEN_KEY_VERSIONthrough the existing deployment secret path.SLACKBOT_EPHEMERAL_API_KEYfor the narrower ephemeral-posting route key./ai-email-status; verify an ephemeral not-connected response./ai-email-connect; verify an ephemeral pairing code and Begin connection button.access_type=offline,prompt=consent,code_challenge_method=S256, and onlygmail.send openid emailscopes.(team_id, user_id)with encrypted refresh token.sent, and audit log omits body./ai-email-disconnect; verify Google revoke call, local grant marked revoked, and pending confirmations invalidated.Deferred Items / Follow-ups
Prompted by: @imfromthebay