fix(seo): request webmasters scope when minting ADC tokens - #109
Open
thelettere wants to merge 1 commit into
Open
fix(seo): request webmasters scope when minting ADC tokens#109thelettere wants to merge 1 commit into
thelettere wants to merge 1 commit into
Conversation
The SEO scripts shell out to `gcloud auth application-default print-access-token` with no `--scopes` argument. With user ADC that silently inherits whatever scopes were stored at login, so it works. With service-account ADC (GOOGLE_APPLICATION_CREDENTIALS) it does not: gcloud mints a cloud-platform-only token and every Search Console call fails with 403 ACCESS_TOKEN_SCOPE_INSUFFICIENT. That makes the scripts unusable from any unattended/headless context, where a service account is the only credential type that isn't subject to interactive reauth policies. Add `adc_access_token()` to _gcloud.py. It requests webmasters.readonly,cloud-platform explicitly, and falls back to an unscoped request when the credential can't mint those scopes — so user ADC that wasn't granted them at login keeps working exactly as before. Verified both paths: - service account: analyze_gsc.py returns data (was 403) - user ADC without the scopes granted: unchanged failure message Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
The SEO scripts mint a Google ADC access token by shelling out to:
with no
--scopesargument, in four places —analyze_gsc.py,list_gsc_sites.py,url_inspection.py,preflight.py.With user ADC this works, because the token silently inherits whatever scopes were stored at
gcloud auth application-default login.With service-account ADC (
GOOGLE_APPLICATION_CREDENTIALS) it does not. gcloud mints acloud-platform-only token, and every Search Console call fails:That makes the SEO skills unusable from any unattended or headless context. This matters because a service account is often the only workable credential there — Workspace orgs can enforce Cloud session-control policies that force-expire any credential built on a human's Google session, regardless of how recently it was refreshed, and a headless run has nobody present to complete the reauth prompt.
Fix
Adds
adc_access_token()to_gcloud.py. It requestswebmasters.readonly,cloud-platformexplicitly, and falls back to an unscoped request when the credential cannot mint those scopes — so a user ADC that was not granted them at login behaves exactly as it does today. The four scripts call it instead of shelling out individually.The fallback is what makes this safe: it repairs the service-account path without changing the user-ADC path.
Verification
Both credential types, against a real Search Console property:
GOOGLE_APPLICATION_CREDENTIALSset)403 ACCESS_TOKEN_SCOPE_INSUFFICIENTSummary: 5 clicks | 514 impressions | CTR 0.97% | Avg position 33.5Also ruled out as alternatives, in case they come up in review: the
CLOUDSDK_AUTH_SCOPESenvironment variable has no effect on ADC token minting, andgcloud config set auth/scopeserrors withSection [auth] has no property [scopes]. A code change is the only route.🤖 Generated with Claude Code