The metadata service for GCP (at least on appengine/gcf/cloud run) allows fetching scoped tokens. This has been implemented in some of the auth clients already (node, go, PR pending for python), but missing from Java and possibly some others.
https://cloud.google.com/functions/docs/securing/function-identity#access_tokens describes how it works.