Field
Field workers (for example drivers or warehouse staff) sign in on an enrolled device with a PIN, at
the platform’s /field/*. The platform issues a short access token bound to the device’s key. The
device sends it to your backend, and the SDK verifies it. PINs never reach your backend. The model is
described in Field workers and the backend side in
Field backend; the wire is in Field protocol.
Configuration
Section titled “Configuration”| Config key | Env var | Default | Meaning |
|---|---|---|---|
flowcatalyst.field.app_code |
FLOWCATALYST_FIELD_APP_CODE |
none, required | This application’s code. Tokens must carry it as aud. |
flowcatalyst.field.app_base_url |
FLOWCATALYST_FIELD_APP_BASE_URL |
APP_URL |
Public origin devices call (scheme://host[:port]). The proof’s htu is checked against this plus the request path. With one origin and no wildcard, the Host header is never read. An application with a host per client can give a list (an array, or a comma-separated string) and/or wildcard entries, and then the request’s host is read; see below. |
flowcatalyst.field.proof_max_age_seconds |
FLOWCATALYST_FIELD_PROOF_MAX_AGE |
300 | How far a proof’s iat may differ from now. Widen for devices with bad clocks. |
flowcatalyst.field.clock_skew_seconds |
FLOWCATALYST_FIELD_CLOCK_SKEW |
60 | Tolerance on exp and nbf. |
The issuer and signing keys come from FLOWCATALYST_BASE_URL (OIDC discovery and JWKS), shared with
the other validators. Without app_code the verifier refuses to construct.
An application with a host per client
Section titled “An application with a host per client”With several entries, or a wildcard, in app_base_url, the guard reads the request’s host and the first
entry it matches gives the origin: that entry’s scheme and port plus the request’s host (never the
request’s own scheme or port, which behind a load balancer are not what the device called). A host that
matches no entry is refused as htu_mismatch (401).
// config/flowcatalyst.php, or FLOWCATALYST_FIELD_APP_BASE_URL as a comma-separated string'app_base_url' => ['https://acme.example.com', 'https://*.example.net'],- A
*must be the whole leftmost label and matches exactly one label (acme.example.netyes,a.b.example.netandexample.netno). It needs at least two labels after it:https://*.comandhttps://*are refused. An entry with no scheme or host, or a misplaced*, throws aLogicException(a 500) on the first field request. - Reading the host is safe only because it merely chooses among origins you listed: someone who gets a device to call a host of theirs holds a proof for that host, which matches no entry. Every wildcard must cover a DNS zone you wholly control, and behind a proxy set Laravel’s trusted proxies so the host is the one the device called.
- You must bind a
FlowCatalyst\Auth\Contracts\FieldClientCheck, or the guard throws aLogicExceptionon the first field request. An application like this almost certainly serves several clients; the SDK checks the token is for this application, not which client it is for, and without a check a worker of one client could call another client’s host. One client on several hosts binds a check that returnstrue.
Protecting routes
Section titled “Protecting routes”The fc.field middleware authenticates with the field guard, which the service provider registers
if your config/auth.php does not define one.
use Illuminate\Http\Request;
Route::post('/api/deliveries', function (Request $request) { /** @var \FlowCatalyst\Auth\Field\FieldPrincipal $worker */ $worker = $request->user(); // or Auth::guard('field')->user() $worker->workerId; $worker->workerCode; $worker->clientIdentifier; $worker->deviceId;})->middleware('fc.field');A verified request carries a FieldPrincipal with workerId, clientId, clientIdentifier,
workerCode, name, appCode, deviceId, deviceMode, sessionId, amr, authTime,
expiresAt, jkt, tokenId, plus actor (a FieldActor with id, type and name, set when
someone signs in as the worker), test and linkedPrincipalId. It is also the Authenticatable of
the field guard (identifier = worker id), so auth:field works, but the middleware gives proper
error responses.
To verify without the middleware:
use FlowCatalyst\Auth\Field\FieldTokenException;use FlowCatalyst\Auth\Field\FieldTokenVerifier;
try { $principal = app(FieldTokenVerifier::class)->verify( $request->header('Authorization'), // "DPoP <token>" $request->header('DPoP'), // the proof $request->method(), $fullUrl, // app_base_url + request path, never from Host );} catch (FieldTokenException $e) { $e->reason; // see below}What is checked
Section titled “What is checked”The access token is RS256 with typ: fc-field+jwt and token_use: "field", addressed to your
application, and bound to the device key (cnf.jkt). The proof is an ES256 JWS signed by that key:
its method, URL and access-token hash must match the request. Any other alg is refused. Replay
protection beyond the proof’s iat window (a nonce) is not done by the SDK.
| Response | When |
|---|---|
403 {"error":"PIN_CHANGE_REQUIRED"} |
The token may only change the PIN. |
401 {"error": <reason>} with WWW-Authenticate: DPoP error="invalid_token" |
Any other refusal. |
503 {"error":"unavailable"} |
Discovery or JWKS could not be fetched. |
The 401 reasons are malformed, wrong_typ, wrong_token_use, wrong_aud, expired,
invalid_token, missing_proof, invalid_proof, jkt_mismatch, htm_mismatch, htu_mismatch,
ath_mismatch and stale_proof. They are constants on FieldTokenException (REASON_*).
The API-token validator behind auth:fc-token refuses any token_use other than api or
identity, so a field token is never an API credential.
Online introspection
Section titled “Online introspection”Verification is offline. To check the session is still live, introspect (needs
platform:iam:field-token:introspect):
$r = FlowCatalyst::introspectFieldToken($token); // ->getActive(), ->getSub(), ->getWorkerCode() ...Administration
Section titled “Administration”Wrappers over the control-plane API, with the permissions platform:iam:field-worker:* and
platform:iam:field-device:*:
$fc = FlowCatalyst::fieldWorkers();$fc->ensure((new EnsureFieldWorkerRequest())->setClientId($cid)->setWorkerCode('W001')->setName('Ann')->setAppCodes(['my-app']));$fc->list($cid, ['appCode' => 'my-app']);$fc->get($id); $fc->update($id, $req); $fc->delete($id);$fc->resetPin($id); // random temporary PIN, returned once; resetPin($id, '482913') sets one$fc->unlock($id); $fc->suspend($id); $fc->activate($id);$fc->grantApp($id, 'my-app'); $fc->revokeApp($id, 'my-app'); $fc->signIns($id, page: 0);$fc->link($id, $principalId); $fc->unlink($id);$fc->issueBadge($id, 'Gate pass'); $fc->listBadges($id); $fc->revokeBadge($id, $badgeId);$fc->bulkIssueBadges([$id1, $id2]);$fc->createSignInCode($id, 'my-app');
$dev = FlowCatalyst::fieldDevices();$dev->createEnrolmentCode((new CreateEnrolmentCodeRequest())->setClientId($cid)->setMode('PERSONAL')->setAppCodes(['my-app']));$dev->list($cid); $dev->get($id); $dev->suspend($id); $dev->activate($id); $dev->revoke($id);
FlowCatalyst::fieldPolicies()->get($cid);FlowCatalyst::fieldPolicies()->update($cid, fn (PutFieldPolicyRequest $r) => $r->setPinMinLength(8)); // read, change, write back
// Photos and unlock keys$fc->setPhoto($id, $bytes); // JPEG, PNG or WebP bytes; the platform re-encodes$image = $fc->getPhoto($id, 'thumb', $etag); // a FieldWorkerPhotoImage; ->notModified when unchanged$fc->removePhoto($id);$fc->listUnlockKeys($id); $fc->revokeUnlockKey($id, $unlockKeyId);FlowCatalyst::fieldPolicies()->deletePhotos($cid); // every photo of the client; cannot be undoneA policy put replaces the whole policy. A member left out goes back to its default, so a
PutFieldPolicyRequest with only requireAttestation also switches unlock keys off (which revokes every key
of the client) and photos back on. update($clientId, $change) reads the policy, lets your callable alter the
request that would store it unchanged, and writes the result (two calls: someone else’s edit in between is
overwritten with what was read); FieldPolicies::toRequest($policy) builds that request. ensure takes an
optional worker code: without one the platform generates it (for example KTM482), and a request without a
code is repeatable only with an idempotency key (setIdempotencyKey). There is no wrapper for the
per-application policy overrides and locks; see
Application overrides and locks.
Request classes are the generated models under FlowCatalyst\Generated\Model. Management is also
available in the console; see Field administration.
Testing
Section titled “Testing”Build a FieldTokenVerifier with a now closure to fix the clock, and drive the middleware with
signed fixtures. For permission-based tests on other guards see Testing.