8000 fix(google): sign in with the scope a Workspace admin delegated, and say which scope is missing by adeelahmad · Pull Request #704 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(google): sign in with the scope a Workspace admin delegated, and say which scope is missing - #704

Merged
adeelahmad merged 2 commits into
mainfrom
claude/project-thread-7expgn
Oct 20, 2026
Merged

adeelahmad merged 2 commits into
mainfrom
claude/project-thread-7expgn

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: a Gmail source signing in as a Workspace service account that acts as a user failed with "Google refused to let … act as …: a Workspace admin gives client id … domain-wide delegation for gmail.readonly,gmail.compose (Admin console › Sec", even when the admin had delegated Gmail to that client. Google matches delegated scopes exactly, so a client delegated all of Gmail (https://mail.google.com/, which backup tools such as the one this key belongs to ask for) is refused gmail.readonly; and the health error was cut at 300 characters, so the fix never showed.

After: a service account acting as someone that Google refuses (unauthorized_client) tries once more with the broader scope that covers what it asked for (google_auth.COVERS: all of Gmail, Calendar or Drive); Lens still makes only the narrower scope's calls. When that is refused too, Lens asks Google one scope at a time and the error names the scopes the delegation lacks, the ones it allows, the client id and the exact comma-separated list to paste, plus Google's own words. Health errors keep up to 1,000 characters.

Motivation and Context

Adeel's Gmail connection through a service account kept failing with delegation he says is allowed.

Steps to reproduce (if appropriate):

Delegate only https://mail.google.com/ (or only gmail.readonly) to a service account's client id, then add a Gmail source with that key, a user and write: yes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote a fragment in changelog.d/.

Done questions (AGENTS.md)

  • Goal: the delegated scope now works and a wrong delegation says exactly what to change; merged on green.
  • Agents: the error is in the source's health, which the API and MCP already return.
  • Zero setup: nothing new.
  • Fewest clicks: one paste in the Admin console, given in full.
  • Configurable: n/a, no new setting.
  • Light: n/a, a few more token calls only when Google refuses.
  • Private and secure: threat model row updated for the broader-scope fallback (token kept in memory only, narrower calls only, scope an admin already gave).
  • Cost: every probe is a google.token row in the activity ledger; no model calls.
  • User decides: uses only what the Workspace admin delegated; defaults unchanged.
  • Upgrades: n/a, no stored-data change.
  • Honest: 8000 the error quotes Google's own answer.
  • Tests (test_gmail_source.py: missing compose named, all-of-Gmail delegation works), docs (docs/processing.md), threat model YAML/JSON updated with the prose.
  • Open standards: RFC 7523 JWT bearer as before; no new dependencies.
  • Reported in the project thread. Refine later: the web form's hint could list the exact paste string too.
  • Reuse: reuses the existing token exchange, split into _form/_swap.

Generated by Claude Code

…say which scope is missing

Google matches domain-wide delegation scopes exactly: a client delegated all of
Gmail was refused gmail.readonly and gmail.compose, and the source's error was
cut at 300 characters before the fix. A service account acting as someone now
falls back to the broader scope the admin gave (google_auth.COVERS); when Google
still refuses, Lens asks scope by scope and names what the delegation lacks,
what it allows and the exact list to paste.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KVJvqdsH8dv8fo642tN9LG
@adeelahmad adeelahmad self-assigned this Oct 20, 2026
A unit launched at NOW and let go through the API at the real time ran
for days once the calendar passed NOW, spent the group's $20 budget and
kept the next tick from launching, so the test failed on main from
2026-10-20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KVJvqdsH8dv8fo642tN9LG
@adeelahmad
adeelahmad merged commit 7d34012 into main Oct 20, 2026
12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-7expgn branch October 20, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0