Skip to content

Call another service with a platform token

Sometimes a function must call another first-party application that accepts FlowCatalyst access tokens. The function holds no client id or secret: it asks its host for a token and sends it as a bearer.

The token belongs to the service account linked to the function’s application. Always that one: there is no per-function service account and no override, and the function’s optional webhook-verifier account (see Declare endpoints, auth, subscriptions and schedules) is not used here. The token is what that account’s client_credentials grant would give: the same claims, the account’s flattened permissions as scope, and the same lifetime as an ordinary access token. Give the application’s service account the roles the target needs and nothing more. See Tokens.

The call is refused when the application has no linked service account, when the account or its principal is deactivated, or when the function did not declare the capability.

func init() {
fn.UsesPlatformToken()
fn.HTTPAllow("other-app.example.com")
fn.Platform("POST /call-other", onCallOther)
}
func onCallOther(w http.ResponseWriter, r *http.Request) {
token, err := fn.PlatformToken(r.Context()) // fn.Refresh() skips the cache
if err != nil {
if errors.Is(err, fn.ErrRetryable) {
fn.Retry(w, 5*time.Second)
return
}
fn.Reject(w, "platform token refused")
return
}
req, _ := http.NewRequestWithContext(r.Context(), http.MethodGet, "https://other-app.example.com/api/ping", nil)
req.Header.Set("Authorization", "Bearer "+token)
resp, err := fn.HTTPClient().Do(req)
// ...
}

The target host must also be in HTTPAllow: the token does not widen what the function may reach.

The host caches the token per function and renews it shortly before it expires (it serves from cache while more than the larger of 60 seconds and 10% of the lifetime remains). Concurrent calls for the same function share one fetch, and a failed fetch is not cached. So call it per request rather than keeping the token yourself.

Force a fresh token (Refresh(), { refresh: true }, refresh_platform_token(), platformToken(true)) only when the target answered 401 with the token you were given, for example because the account’s roles changed.

Code Meaning Retryable
NOT_DECLARED the version does not declare the capability no
NOT_ALLOWED the platform refused: not declared there, the application has no linked service account, or the account is inactive. The message carries the platform’s code no
UNAVAILABLE the platform was unreachable, answered 5xx, 429 or 408 yes
DEADLINE the call’s deadline passed no

A runner that predates the capability answers UNKNOWN_OP; the SDKs turn that into an error saying the runner does not support platform tokens, not a crash.

  • Never log the token, at any level. Do not return it to a caller either.
  • Every mint is audited against the service account (operation TOKEN_MINTED_FOR_FUNCTION); the token itself is never recorded.
  • The token is not narrowed by audience or scope per target. It carries the account’s full permissions.
  • The target application must accept FlowCatalyst tokens, verified against the platform’s signing keys.