Guzzle can do this out of the box! This technique is also used to power some of the checks in Oh Dear.
PHP
Flare now uses OAuth for MCP, the CLI, and API
We explain how Flare now uses OAuth to connect MCP clients, the CLI, and the API with scoped permissions instead of broad long-lived tokens. The new flow makes setup faster, adds read-only and project-level access Read more…