geeViz.eeAuth.server¶
FastAPI proxy for Earth Engine that injects per-tenant SA tokens.
The proxy receives requests from EE clients (browser JS, Python SDK
via geeViz.eeAuth.client), looks up the requested tenant in the SA
registry, mints a token (cached), and forwards to the real EE endpoint
with the right Authorization and x-goog-user-project headers.
Two ways to use:
Standalone:
python -m geeViz.eeAuth --port 8888
or programmatically:
from geeViz.eeAuth.server import create_proxy_app app = create_proxy_app() # serve with uvicorn / etc.
Mounted in an existing FastAPI app:
from fastapi import FastAPI from geeViz.eeAuth.server import build_proxy_router app = FastAPI() app.include_router(build_proxy_router(), prefix="/ee-api")
Tenant routing — the proxy picks the SA in this order:
X-geeViz-Credsrequest header (server-side EE SDK; set bygeeViz.eeAuth.client.TenantAwareHttp).?tenant=query string parameter (browser map iframes).Default tenant (the registry’s
defaultentry, loaded fromGEE_SERVICE_ACCOUNT_B64).
Workload tagging — every POST is stamped with a workload tag
ee-proxy__<tenant> in the query string for billing attribution.
Pass workload_tag_builder=... to build_proxy_router if you want
to construct your own tag (e.g. include user / session).
Functions
|
Build a FastAPI |
|
Build a standalone FastAPI app with the proxy mounted at |
- geeViz.eeAuth.server.build_proxy_router(creds=None, upstream: str = 'https://content-earthengine.googleapis.com', tenant_header: str = 'X-geeViz-Creds', tenant_query_param: str = 'tenant', tenant_resolver: Callable[[Request, str], str] | None = None, workload_tag_builder: Callable[[Request, str], str] | None = None) APIRouter[source]¶
Build a FastAPI
APIRouterthat handles{path:path}and proxies every request toupstreamwith the right SA token.- Parameters:
creds – Object exposing
get_token(tenant, force_refresh=False) -> {access_token, project_id, tenant, ...}. Accepts anEECredsinstance, anSARegistry, or any other object with the same interface.None(default) uses the process-wide env-var registry (legacy).upstream – Base URL of the real EE API.
content-earthengine.googleapis.comworks for both maps and compute.earthengine.googleapis.comis also accepted for most endpoints.tenant_header – Header name to read for routing. Default
X-geeViz-Creds. Must match the client side.tenant_query_param – Query string key to read for tenant routing (browser iframe pattern). Default
"tenant". Stripped from the outbound URL so EE never sees it.tenant_resolver – Custom function
(request) -> strto pick the tenant. Override for richer auth schemes (e.g. resolve via IAP email lookup). Default readstenant_headerthentenant_query_param.workload_tag_builder – Custom function
(request, tenant) -> strthat returns the workload tag for billing attribution. Returning""disables tagging on this request. Default buildsee-proxy__<tenant>.
Mount the returned router on whatever prefix you like — typically
/ee-api.
- geeViz.eeAuth.server.create_proxy_app(creds=None, upstream: str = 'https://content-earthengine.googleapis.com', tenant_header: str = 'X-geeViz-Creds', tenant_query_param: str = 'tenant', tenant_resolver: Callable[[Request, str], str] | None = None, workload_tag_builder: Callable[[Request, str], str] | None = None, prefix: str = '/ee-api', serve_geeview: bool = True) FastAPI[source]¶
Build a standalone FastAPI app with the proxy mounted at
prefix. Suitable for direct serving viauvicornor for testing.credsaccepts anEECreds/SARegistry-like object;Nonefalls back to the env-var registry. Seebuild_proxy_router()for the other parameters.Use
build_proxy_routerdirectly if you want to mount in an existing FastAPI app and share its middleware / lifecycle.- Parameters:
serve_geeview – When True (default for standalone runs), also mount the geeView frontend bundle at
/geeView/*. This makes the detached proxy the single long-lived server for both EE auth (/ee-api/*) andMap.view()HTML (/geeView/...). Same origin, same port — browser tabs survive script exits without a daemon-thread server inside each script. Set False to keep the proxy auth-only.