Skip to content

Auth

The Java SDK authenticates outgoing calls to the platform. It offers two modes. It does not validate bearer tokens that arrive at your own service; the only verifier in the SDK is for field-worker tokens. Use your framework’s JWT support, with the platform’s JWKS, to authenticate incoming users.

For a service that acts as itself, with an application’s or a developer’s service account:

var client = FlowCatalystClient.builder()
.baseUrl("https://platform.example.com")
.clientCredentials("oac_your_client_id", "your_client_secret")
.build();

The SDK obtains tokens with the OAuth2 client_credentials grant, posting the id and secret in a form body to {baseUrl}/oauth/token (or to tokenUrl(...) if you set one).

  • Use a service account. A plain login client is rejected by the platform’s token endpoint.
  • Caching. The token is kept in memory and refreshed when it is within 60 seconds of expiry.
  • Single flight. Concurrent callers share one fetch: they block on the in-progress request instead of issuing their own.
  • Refresh on 401. If a request is answered 401, the SDK discards the cached token, fetches a new one and repeats the request once. A second 401 surfaces as SdkError.TokenExpired.

The manager is available as client.tokenManager() (null in user-token mode) with getToken(), refreshToken() and clearCache().

SdkError When
MissingCredentials The id or secret is empty.
InvalidCredentials The token endpoint answered 401 or 403.
TokenFetchFailed The token call failed: a network error, an interrupt, a non-2xx status other than 401 and 403 (the status leads the message), or a response with no access_token.
TokenExpired A request was rejected with 401 and could not be repaired by the one refresh.

For code that calls the platform as a signed-in user, for example with a token your login flow obtained:

var client = FlowCatalystClient.builder()
.baseUrl("https://platform.example.com")
.accessToken(() -> session.currentAccessToken()) // or .accessToken("static-token")
.build();

The host application owns refresh. The SDK calls the supplier before every request; a 401 is surfaced, not retried. If the supplier throws, the failure is reported as SdkError.TokenExpired.

Which token to use for what is explained in tokens: an id_token is an assertion to your application and cannot act as the user, whereas an access token minted for an API-access client can. See call the API.

Both modes are a TokenProvider, a one-method interface (String getToken()). It is what the transport calls. You will rarely implement it: accessToken(Supplier<String>) wraps a supplier for you.

A request is repeatable when its method is GET, HEAD, OPTIONS, PUT or DELETE, or when the caller marks it for that one call (postRepeatable(...), or the repeatable argument of exchange; the SDK marks the declarative syncs). The transport retries with exponential backoff and follows one rule:

  • 408 and 429 (refused before the platform processed the request) are retried for every request. So is a connection that was never made: DNS, refused, a connect timeout, a TLS handshake failure.
  • 502, 503 and 504, and a transport failure after the request may have been sent (a reset, EOF, the request timeout), are retried only for a repeatable request. Any other request, such as a plain POST that creates something, is not sent again: the call throws FlowCatalystException carrying SdkError.OutcomeUnknown (the platform may have applied it; read the state before you send it again).
  • A DELETE that answers 404 on a retry after an attempt whose outcome was unknown succeeds with no body.
  • 500 is not retried, because a 500 may have done the work. An interrupt is never retried.
Setting Default Builder method
Retries 3, so up to four requests in all (0 turns retries off) retryAttempts(int)
Base delay 100 ms, doubled each attempt retryDelay(Duration)
Request timeout 30 s timeout(Duration)

A timeout becomes SdkError.Timeout (or OutcomeUnknown, when it came after a request that is not repeatable was sent); a connection failure, an unreadable response, or an interrupt becomes SdkError.Network. The retry delay is the backoff above: it does not honour a Retry-After header. Once retries are spent a 429 surfaces as SdkError.RateLimited, whose retryAfter is read from the error body’s retryAfter member (seconds) when the platform sends one.

routerBaseUrl(...) sets the base URL for client.router() calls, which go to the message router rather than the platform. If it is unset the calls use baseUrl, which is correct only when both run on one host, as they do under fcdev.