Skip to content

Field workers

Field workers (for example drivers or warehouse staff) sign in on an enrolled device with a PIN, at the platform’s /field/* endpoints. The platform issues a short access token bound to the device’s key; the app’s backend receives it with a proof of possession. PINs never reach your backend. The SDK’s job on the backend is to verify, and, separately, to let an administrative service manage workers. For the model, see Field workers, and for the end-to-end guide Field backend and Field admin. The wire rules are in Field protocol. The client side is in the field libraries (field-js, React Native).

Authorization: DPoP <access token>
DPoP: <proof>

The token is RS256 with JOSE typ: fc-field+jwt, token_use: "field" and aud set to your application code, with the device key’s thumbprint in cnf.jkt. The proof is an ES256 JWS signed by that same device key, naming the HTTP method and URL and a hash of the token. Only RS256 tokens and ES256 proofs are accepted.

import Fastify from 'fastify';
import { fieldAuth } from '@flowcatalyst/sdk/fastify';
const app = Fastify();
await app.register(fieldAuth, {
issuer: 'https://auth.example.com', // the platform base URL and the token's iss
appCode: 'my-app', // tokens must be addressed to this application
publicBaseUrl: 'https://api.my-app.example.com',
});
app.post('/orders', { preHandler: app.fcField.require() }, async (req) => {
const p = req.fieldPrincipal!; // workerId, workerCode, deviceId, clientId, appCode, ...
return { worker: p.workerCode };
});

publicBaseUrl matters: the proof’s htu claim is checked against publicBaseUrl plus the request path (the query is ignored). The Host header is never used, so a spoofed host cannot change the check. Include any proxy path prefix in publicBaseUrl.

fieldAuth adds no global hook. It only runs on routes that use app.fcField.require() and never touches request.principal, so it coexists with flowcatalystAuth in the same app. Responses:

Situation Response
Valid the route runs; request.fieldPrincipal is set
Token is for changing a PIN only 403 { "error": "PIN_CHANGE_REQUIRED" }
Any other refusal 401, WWW-Authenticate: DPoP error="invalid_token", { "error": "<reason>" }
Discovery or key fetch failed 503 { "error": "unavailable" }

FieldAuthOptions extends FieldTokenVerifierConfig with publicBaseUrl:

Option Default Meaning
issuer required Platform base URL; also the expected iss.
appCode required Expected aud.
publicBaseUrl required (plugin) This service’s public origin, used for the htu check.
jwksUrl from discovery Fetch keys from this URL instead of /.well-known/openid-configuration.
keys none A jose key resolver, bypassing discovery and fetching. For tests and offline fixtures.
fetch global fetch Transport for discovery.
clockSkewSeconds 60 exp and nbf skew.
proofMaxAgeSeconds 300 How far the proof’s iat may be from now, either way. Widen it for devices with bad clocks.
now system clock Clock override for tests.
import { FieldTokenVerifier, FieldError, FieldVerifierUnavailableError } from '@flowcatalyst/sdk';
const verifier = new FieldTokenVerifier({ issuer, appCode: 'my-app' });
try {
const p = await verifier.verify(
req.headers.authorization,
req.headers.dpop as string | undefined,
'POST',
'https://api.my-app.example.com/orders', // scheme, host and path; query ignored
);
} catch (e) {
if (e instanceof FieldError) return reply.code(401).send({ error: e.reason });
if (e instanceof FieldVerifierUnavailableError) return reply.code(503).send();
throw e;
}

verifyFieldToken(config, authorization, dpop, method, url) is a one-shot wrapper. The verifier caches the platform’s keys and refreshes on an unknown key id; a failed discovery is not memoised.

FieldError.reason is one of these stable strings (exported as FieldReason): malformed, wrong_typ, wrong_token_use, wrong_aud, expired, invalid_token, pcr, missing_proof, invalid_proof, jkt_mismatch, htm_mismatch, htu_mismatch, ath_mismatch, stale_proof. pcr is a token that may only be used to change a PIN. The verifier does not do nonce replay protection: the proof’s iat window is the replay bound.

FieldPrincipal carries: workerId, clientId, clientIdentifier, workerCode, name, appCode, deviceId (empty on an unenrolled key), deviceMode (PERSONAL, SHARED or UNENROLLED), sessionId, amr, authTime, expiresAt, jkt, tokenId, actor, test and linkedPrincipalId. When actor is set, someone else (a supervisor or a platform user) is signed in as the worker: every other field is still the worker’s, so record the worker as the subject of the action and actor as the operator. linkedPrincipalId is for audit correlation and grants nothing.

The offline check proves the token and key; it does not know whether the session is still live. When that matters, ask the platform:

const result = await client.introspectFieldToken(token); // or client.fieldTokens().introspect(token)

The admin API needs a service account or user token with the field permissions, and is used from a back-office service, not from the field devices:

await client.fieldWorkers().ensure({ clientId, workerCode: 'W001', name: 'Wendy', appCodes: ['my-app'] });
await client.fieldWorkers().resetPin(id); // the temporary PIN is returned once
await client.fieldDevices().createEnrolmentCode({ clientId, mode: 'SHARED', appCodes: ['my-app'] });
await client.fieldPolicies().update(clientId, (policy) => { policy.pinMinLength = 8; }); // read, change, write back

A policy put replaces the whole policy. A member you leave out goes back to its default, so put(clientId, { requireAttestation: true }) also switches unlock keys off (which revokes every key of the client) and photos back on. Use update(clientId, change): it reads the policy, lets change alter the request that would store it unchanged, and writes the result, so every member change does not touch keeps its value (members this SDK does not know included). The read and the write are two calls: a policy edited by someone else in between is overwritten with what was read. put is for sending a whole policy you built.

Resource Methods
fieldWorkers() ensure, list, get, update, delete, resetPin, unlock, suspend, activate, grantApp, revokeApp, issueBadge, listBadges, revokeBadge, bulkIssueBadges, createSignInCode, link, unlink, signIns, setPhoto, getPhoto, removePhoto, listUnlockKeys, revokeUnlockKey
fieldDevices() createEnrolmentCode, list, get, suspend, activate, revoke
fieldPolicies() get, put, update, deletePhotos (per client: PIN length and re-authentication, lock thresholds, idle time, attestation, badge-only login, worker code digits, photos, unlock keys)
fieldTokens() introspect

ensure is idempotent by worker code and grants the listed applications additively. The workerCode is optional: without one the platform generates one (three letters and the client policy’s workerCodeDigits digits, for example KTM482) and returns it, and a request without a code creates a new worker every time unless it carries an idempotencyKey (up to 100 characters), in which case a repeat answers the worker the first request made and the SDK treats the call as safe to resend after a lost answer. A key together with a code is refused. An enrolment code is created for PERSONAL (optionally assignedWorkerId) or SHARED devices. Request and response types are exported, for example EnsureFieldWorkerRequest, FieldDeviceDto and PutFieldPolicyRequest. All calls return ResultAsync values; see Errors.

await client.fieldWorkers().setPhoto(id, bytes, 'image/jpeg'); // Blob, Uint8Array or ArrayBuffer; JPEG, PNG or WebP
const photo = await client.fieldWorkers().getPhoto(id, { size: 'thumb', ifNoneMatch: etag });
// photo: { bytes?, contentType?, etag?, notModified }
await client.fieldWorkers().removePhoto(id); // not an error when there is none
await client.fieldPolicies().deletePhotos(clientId); // { removed }: every photo of the client; cannot be undone
const { unlockKeys } = await client.fieldWorkers().listUnlockKeys(id); // newest first, live and revoked
await client.fieldWorkers().revokeUnlockKey(id, unlockKeyId); // ends the key and the sessions it signed in

(Shown without the ResultAsync handling.) setPhoto and removePhoto need platform:iam:field-worker:manage; reads need view. The platform re-encodes the image, so the original bytes are not stored. deletePhotos is refused to an application-confined service account. The admin API returns a key’s status, device, lastUsedAt, liveSessions and the parsed attestation, never its public half. See Manage workers, devices, badges and impersonation.

There is no hand-written wrapper for the per-application policy overrides and locks (/api/field-policies/{clientId}/applications and /locks); call them through the generated operations or the HTTP API. See Application overrides and locks.

The SDK’s tests need no platform. They generate an RSA key pair for the platform and an EC key pair for a device with jose, mint a token and a proof with the claims under test, and pass the platform’s public key as a local key set through the keys option:

import { createLocalJWKSet } from 'jose';
const verifier = new FieldTokenVerifier({
issuer: 'https://fc.example.test',
appCode: 'test-app',
keys: createLocalJWKSet({ keys: [platformPublicJwk] }),
now: () => new Date('2026-01-01T00:00:00Z'),
});

Test each refusal reason by altering one claim (a wrong aud, a proof for another htu, a proof older than proofMaxAgeSeconds). For route tests, register fieldAuth with the same keys option and call the route with app.inject.