Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ META_ACCESS_TOKEN_NIKE=
TIKTOK_ACCESS_TOKEN_ACME=
TIKTOK_ACCESS_TOKEN_NIKE=
GOOGLE_ADS_TOKEN_ACME=
GOOGLE_ADS_DEVELOPER_TOKEN=
FACEBOOK_ACCESS_TOKEN_ACME=
INSTAGRAM_ACCESS_TOKEN_ACME=
TIKTOK_ORGANIC_ACCESS_TOKEN_ACME=
Expand All @@ -56,14 +55,19 @@ PINTEREST_ACCESS_TOKEN_ACME=
GA4_ACCESS_TOKEN_ACME=
GTM_ACCESS_TOKEN_ACME=

# ─── Pipeline - YouTube OAuth (consent + connector) ─────────────────────────
# Generic keys (no client literal) read/written by
# scripts/youtube_oauth_consent.py: client id + secret are read from .env, the
# refresh token is written back after the consent flow. The YouTube connector
# resolves its own env names from oauth_client_id_env / oauth_client_secret_env
# / oauth_refresh_token_env in clients/<client>.yml, so point them at these
# keys (or at suffixed variants for per-client setups, e.g. YOUTUBE_OAUTH_*_NIKE
# + `python scripts/youtube_oauth_consent.py --env-suffix _NIKE`).
# ─── Pipeline - Google Unified OAuth (GA4, GTM, Google Ads, YouTube) ────────
# Run `make auth-google` (or `multitenant-elt auth google`) to run the interactive renewal wizard.
# Global Agency credentials (shared across clients via MCC / manager permissions):
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_REFRESH_TOKEN=

# Client-specific Google OAuth overrides (optional per-client isolation):
# GOOGLE_OAUTH_CLIENT_ID_ACME=
# GOOGLE_OAUTH_CLIENT_SECRET_ACME=
# GOOGLE_OAUTH_REFRESH_TOKEN_ACME=

# Legacy YouTube OAuth keys (backwards compatibility):
YOUTUBE_OAUTH_CLIENT_ID=
YOUTUBE_OAUTH_CLIENT_SECRET=
YOUTUBE_OAUTH_REFRESH_TOKEN=
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **Unified Google OAuth Renewal Wizard**: Added `multitenant-elt auth google` CLI command and `make auth-google` target to obtain and store permanent OAuth refresh tokens for all Google integrations (Google Ads, GA4, GTM, and YouTube). Supports both global agency credentials (via MCC / manager permissions) and client-isolated credentials (`_CLIENT` suffix).
- **Automated Token Management**: Added `GoogleTokenManager` with automatic caching, proactive refresh before expiry, and automatic token invalidation and refresh on HTTP 401 Unauthorized responses across Google Ads, GTM, and YouTube connectors.

### Changed

- **Sunset Google Ads Developer Token**: Completely removed all references to `developer_token` / `GOOGLE_ADS_DEVELOPER_TOKEN` across code, schemas, and documentation following Google Ads API developer token sunset on September 9, 2026. Developer tokens are now ignored by the API and authorization is bound directly to Google Cloud projects.
- **Hierarchical Credential Resolution**: Google connectors now look up client-specific OAuth refresh keys first (`GOOGLE_OAUTH_*_{CLIENT}`), then fall back to global agency keys (`GOOGLE_OAUTH_*`), and finally legacy connector-specific variables for backwards compatibility.

## [1.3.0] - 2026-11-04

### Added
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TOOLS := tools/bin
.PHONY: lint-docker lint-actions lint-all test-security
.PHONY: tools reinstall doctor
.PHONY: clean pristine
.PHONY: setup-networks setup-env pipeline auth-meta
.PHONY: setup-networks setup-env pipeline auth-meta auth-google
.PHONY: docker-build docker-build-pipeline
.PHONY: docker-up docker-up-all docker-down docker-logs
.PHONY: docker-db docker-pipeline docker-metabase
Expand Down Expand Up @@ -148,6 +148,9 @@ pipeline: ## Run pipeline orchestration
auth-meta: ## Run interactive Meta token renewal wizard (usage: make auth-meta [CLIENT=acme])
@uv run python main.py auth meta $(if $(CLIENT),--client $(CLIENT),)

auth-google: ## Run interactive Google OAuth renewal wizard (usage: make auth-google [CLIENT=acme] [SERVICES=all])
@uv run python main.py auth google $(if $(CLIENT),--client $(CLIENT),) $(if $(SERVICES),--services $(SERVICES),)

# === DOCKER - BUILD ========================================================

docker-build: ## Build all images (OCI labels: REVISION=local + CREATED now)
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ See [.env.example](.env.example) for the full list of environment variables.
|---|---|
| **Database** | `POSTGRES_PASSWORD`, `DESTINATION__POSTGRES__CREDENTIALS__*` |
| **Meta Ads** | `META_ACCESS_TOKEN_{CLIENT}` |
| **Google Ads** | `GOOGLE_ADS_DEVELOPER_TOKEN`, `GOOGLE_ADS_ACCESS_TOKEN_{CLIENT}` |
| **Google Suite (Ads, GA4, GTM, YouTube)** | `GOOGLE_OAUTH_CLIENT_ID`, `GOOGLE_OAUTH_CLIENT_SECRET`, `GOOGLE_OAUTH_REFRESH_TOKEN` (or per-client `_CLIENT`) |
| **Facebook** | `FACEBOOK_ACCESS_TOKEN_{CLIENT}` |
| **Instagram** | `INSTAGRAM_ACCESS_TOKEN_{CLIENT}` |
| **Pipeline** | `CLIENTS_DIR`, `TELEGRAM_BOT_TOKEN`, `TELEGRAM_CHAT_ID` |
Expand Down Expand Up @@ -318,6 +318,14 @@ All tests are mock-based - no live API calls. Each connector has tests for succe
make auth-meta
# Or for a specific client:
make auth-meta CLIENT=acme

# Interactive Google OAuth Renewal Wizard (GA4, GTM, Google Ads, YouTube)
# Generates durable Refresh Tokens and configures global agency or per-client credentials
make auth-google
# Or for a specific client:
make auth-google CLIENT=acme
# Or restrict to specific services (default: all):
make auth-google SERVICES=ga4,gtm
```

---
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies = [
"pyyaml>=6.0",
"requests>=2.31",
"python-dotenv>=1.0",
"google-auth>=2.0",
]

[project.urls]
Expand Down
38 changes: 38 additions & 0 deletions src/agency_analytics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def cmd_auth_meta(args):
)


def cmd_auth_google(args):
from agency_analytics.google_auth import run_google_auth_wizard

services = [s.strip() for s in args.services.split(",")] if args.services else ["all"]
return run_google_auth_wizard(
client_name=args.client,
services=services,
client_id=args.client_id,
client_secret=args.client_secret,
env_path=args.env_path,
interactive=not args.non_interactive,
)


def cli():
parser = argparse.ArgumentParser(
prog="multitenant-elt",
Expand Down Expand Up @@ -132,6 +146,30 @@ def cli():
)
p_meta.set_defaults(func=cmd_auth_meta)

p_google = auth_subparsers.add_parser(
"google",
help="Interactive unified Google OAuth refresh token wizard (Ads, GA4, GTM, YouTube)",
)
p_google.add_argument(
"--client",
default=None,
help="Target client ID for per-client keys, or omit for global agency credentials",
)
p_google.add_argument(
"--services",
default="all",
help="Comma-separated services: all, ga4, gtm, google_ads, youtube (default: all)",
)
p_google.add_argument("--client-id", default=None, help="Google OAuth Client ID")
p_google.add_argument("--client-secret", default=None, help="Google OAuth Client Secret")
p_google.add_argument("--env-path", default=".env", help="Path to .env file (default: .env)")
p_google.add_argument(
"--non-interactive",
action="store_true",
help="Run without interactive prompts (fails if required flags are omitted)",
)
p_google.set_defaults(func=cmd_auth_google)

args = parser.parse_args()
return args.func(args)

Expand Down
4 changes: 2 additions & 2 deletions src/agency_analytics/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def output_schema(client_id: str) -> str:
# applies its default silently; ``groups`` holds all-or-none key groups (the
# youtube OAuth trio, C-S4); ``env_keys`` lists YAML keys whose values name
# environment variables and ``env_globals`` fixed env names (google's
# GOOGLE_ADS_DEVELOPER_TOKEN, read at run_google.py:240). Types are
# optional globals (e.g. legacy global keys). Types are
# str|int|bool only; ``int`` excludes bool and ``bool`` requires exact type.
CONNECTOR_CONTRACT: dict[str, dict[str, Any]] = {
"meta": {
Expand All @@ -111,7 +111,7 @@ def output_schema(client_id: str) -> str:
"required": {"customer_id": str, "token_env": str},
"optional": {},
"env_keys": ["token_env"],
"env_globals": ["GOOGLE_ADS_DEVELOPER_TOKEN"],
"env_globals": [],
},
"facebook": {
"required": {"page_id": str, "token_env": str},
Expand Down
Loading
Loading