Field workers
Field workers (for example drivers or warehouse staff) do not have platform accounts. They sign in to the
platform with a worker code and a PIN from an enrolled device, through the platform’s /field/* routes and the
field client libraries. The platform issues a short field access token bound to the device’s key. Your
application never sees a PIN and hosts no field login: it only verifies what the device presents on each request. For
the identity model see field workers; the framework rules are section 15 of the sessions
and login specification.
Field authentication is off by default. Sessions and bearer tokens work as before.
Turning it on
Section titled “Turning it on”It needs application(code) (a token’s audience must equal your application code) and auth.cookie-keys (the
nonces below derive from them). Without either, start-up fails with a message that says which. The DPoP
authorization scheme then works on every route that requires a context; without the opt-in it is answered 401.
AuthModule.builder() .application(new ApplicationCode("orders")) // a token's audience must equal this .fieldWorkers(FieldOptions.builder() .permissions(FieldPermissions.byDeviceMode(Set.of("orders:gate:open", "orders:gate:view"), Set.of("orders:gate:view"))) .replayCache(lookup -> RedisFieldReplayCache.create(lookup.get(RedisConnections.class).defaultInstance())) .build()) .build()FieldOptions also takes proofWindow (default 24 hours).
m, err := d.Build(ctx, b, auth.SessionStore(authredis.Factory(clients)), auth.Application(fw.MustApplicationCode("orders")), auth.FieldWorkers( auth.MapFieldPermissions(auth.FieldPermissionsByDeviceMode( []string{"orders:thing:create", "orders:thing:view"}, // PERSONAL device []string{"orders:thing:view"}, // SHARED kiosk )), auth.FieldReplay(replay), // a shared cache when there is more than one replica ),)The OpenAPI document is written in the declare phase, before Build, so pass auth.DeclareFieldWorkers() to
auth.Declare as well as auth.FieldWorkers to Build. Build fails when only one of them is given.
When field workers are on, the OpenAPI document lists the dpop security scheme (HTTP scheme DPoP, bearerFormat
fc-field+jwt), and context operations list session, bearer and dpop. Without field workers the document is
unchanged.
What a request looks like
Section titled “What a request looks like”Authorization: DPoP <field access token> and DPoP: <proof> (RFC 9449). The framework checks, in order:
- The token, with the same keys, cache and issuer as bearer tokens, RS256 only: JOSE
typfc-field+jwt,iss,audequal to your application code,exp/nbf/iat,token_usefield,substartingfwu_, andclient_id,client_identifier,sidandcnf.jktpresent.device_idis absent on a device that is not enrolled (device_modeUNENROLLED). Adevice_modethat is neitherPERSONALnorSHAREDis treated asSHARED, the lesser permission set. Apcrclaim (a temporary-PIN token, valid only on the platform’s PIN change) is answered403 PIN_CHANGE_REQUIRED. - The proof: an ES256 JWS signed by the key named in its header, whose RFC 7638 thumbprint equals the token’s
cnf.jkt;htmequals the method;htuequalsauth.public-base-urlplus the request path (no query; theHostheader is never used);athis the hash of the token;jtiis present;iatis within the window. - The application nonce and the replay cache.
| Situation | Answer |
|---|---|
| any refusal of the token or the proof | 401 UNAUTHENTICATED, WWW-Authenticate: DPoP error="invalid_token" (the reason is logged at debug level) |
| no nonce, or one that is not valid | 401 USE_DPOP_NONCE, WWW-Authenticate: DPoP error="use_dpop_nonce". The client retries once with the nonce in the response |
a pcr token |
403 PIN_CHANGE_REQUIRED |
| the platform’s keys or the replay cache cannot be read | 503 UNAVAILABLE |
There is no fall-back to the session cookie, CSRF does not apply (as for bearer tokens), and a 401 is never turned
into a redirect. Every response to a DPoP request carries a fresh DPoP-Nonce header, success or error, so a client
rarely needs the retry.
Nonces
Section titled “Nonces”Field devices keep bad time, so a proof’s iat is accepted within 24 hours of your clock and freshness comes from a
nonce. The platform’s nonces are stored platform-side, so your application issues its own, statelessly: a nonce is
the five-minute bucket and a MAC of it under a key derived (HKDF-SHA256) from your cookie key. It is valid in its
bucket and the next, under any configured cookie key, so rotating auth.cookie-keys does not break devices. Removing a
key from the list does invalidate the nonces made with it. Nothing is stored.
The replay cache
Section titled “The replay cache”A proof’s jti is remembered per device key for 11 minutes. The default is in memory, and start-up logs one
warning saying so: with more than one replica a captured proof can be replayed against another replica inside the
window. Applications with several replicas pass the Redis cache (key fw:dpop:{jkt}:{jti}, SET NX PX):
RedisFieldReplayCache, in framework-auth-redis.
cache, err := authredis.ReplayCacheOf(clients) // the default Redis instance// ...auth.FieldReplay(cache)A cache that cannot be reached answers 503: a proof is never accepted unchecked. Replay also needs the access token
(because of ath) and is limited to the same method and URL.
In your routes
Section titled “In your routes”The request’s Context has the principal fwu_... with kind FIELD_WORKER, the worker’s name as the subject name
(the token’s name; an operator signed in as the worker is the actor), the client from the token
(client_identifier: a field worker belongs to exactly one client), the application, and the permissions from your
field mapping.
A request for another client is refused. Your client selector is consulted for field workers too. When it names a
client other than the worker’s (an application that takes the client from the path, /api/clients/globex/..., with a
worker of acme), the answer is 403 CLIENT_NOT_PERMITTED, the same as for a user of another client, before your
field permission resolver runs. When it names the worker’s own client or the platform (no client named), the context’s
client is the worker’s. So a handler need not compare the path’s client with the worker’s itself. The selector sees the
worker as a principal of kind FIELD_WORKER with no clients; return the platform client rather than throwing for one
you do not recognise.
routes.post("/api/v1/gates/open", gates::open, RouteOptions.requiresContext() .with(Auth.requireSource(Authenticated.Source.FIELD)) .with(Auth.require("orders:gate:open")));
Optional<FieldPrincipal> worker = Auth.current(request).orElseThrow().field();rt.HandleContext("POST /api/field/only", handler, httpfw.With(auth.RequireSource(auth.SourceField)))rt.HandleContext("POST /api/field/never", handler, httpfw.With(auth.RequireSource(auth.SourceSession, auth.SourceBearer)))auth.Current(r) gives the Authenticated with Source auth.SourceField and Field, a *auth.FieldPrincipal.
FieldPrincipal holds the worker id and code, name, client id and identifier, application code, device id (empty when
unenrolled), device mode (PERSONAL, SHARED or UNENROLLED), the actor (who is signed in as the worker), the
authentication methods and time, the session id, the expiry and the thumbprint of the device key the token is bound to
(cnf.jkt; a push ticket bound to a key is checked against it). The linked platform user, if
any, is for audit correlation only and grants nothing: no permission, role or tier comes from it. A field worker
has no roles, applications, clients or tier: no platform authority.
Use requireSource to make a route field-only (FIELD) or never-field (SESSION and BEARER).
Permissions are yours to map
Section titled “Permissions are yours to map”Field permissions are mapped separately from sessions and bearer tokens. The default grants none, so a route that
requires a permission refuses field workers until you map them. A fixed set (FieldPermissions.all(...) /
auth.FieldPermissionsAll(...)) or one set per device mode (byDeviceMode(personal, shared), which gives shared
kiosks less) cover most cases.
If the application keeps a worker’s roles in its own store, give a resolver instead. It is called on every authenticated
field request with the request and the verified FieldPrincipal, and returns the permissions. Empty or null grants
nothing. If it throws or returns an error, the request answers 503 UNAVAILABLE (with a fresh DPoP-Nonce), never
“no permissions” and never 401 or 403, so a store outage makes the device retry. The last of the mapping and the
resolver given wins.
FieldOptions.builder().permissionResolver((request, worker) -> /* permissions */ ...)auth.FieldWorkers(auth.FieldPermissionsFrom( func(ctx context.Context, p auth.FieldPrincipal) ([]string, error) { return roles.PermissionsOf(ctx, p.WorkerID, p.ClientIdentifier) // your database }))FieldTokens (Java; provided when field workers are on) verifies a token on its own, without a proof, for a check outside
the request path.
Before a high-value action: live check
Section titled “Before a high-value action: live check”Access tokens live ten minutes, so a revoked device or a suspended worker keeps a valid token until it expires. For an
action that cannot wait (opening a gate, releasing a load), add the live check. It calls the platform’s POST /api/field-tokens/introspect with your application’s service account, which needs the permission
platform:iam:field-token:introspect.
routes.post("/api/v1/gates/open", gates::open, RouteOptions.requiresContext() .with(Auth.requireSource(Authenticated.Source.FIELD)) .with(RequireLiveField.of(app, Duration.ofSeconds(30))));rt.HandleContext("POST /api/gate/open", open, httpfw.With(fc.RequireLiveField(30*time.Second)))active: false:401 UNAUTHENTICATEDwithWWW-Authenticate: DPoP error="invalid_token".- The platform cannot be asked (unreachable, refuses the service account, answers nonsense, or the module is disabled):
503 UNAVAILABLE. It fails closed. - An active answer is remembered per login family (
sid) for the given time (zero: always ask) and never past the token’s own expiry. An inactive answer is not remembered. - A request that is not a field worker’s is answered
403 FORBIDDEN. A presentsubthat differs from the request’s worker counts as inactive.
Revocation events
Section titled “Revocation events”The platform emits platform:iam:field-worker:suspended, platform:iam:field-device:revoked and
platform:iam:field-session:revoked. They are for application state (cached work assignments, open gate sessions),
not for token validity: tokens expire on their own within ten minutes. Declare the subscription so the definition sync
registers it. The handler may run more than once for one event, so make it idempotent. Data that lacks what its type
needs is rejected, not retried; an error returned from the handler is a transient failure and the platform delivers
again. See receivers.
Receivers receivers = app.get(Receivers.class);receivers.onFieldRevocation((ctx, event) -> { switch (event) { case FieldRevocation.WorkerSuspended w -> assignments.dropFor(w.workerId()); case FieldRevocation.DeviceRevoked d -> gates.closeFor(d.deviceId()); case FieldRevocation.SessionRevoked s -> gates.closeSession(s.sessionId()); }});Subscribe with FieldRevocation.subscription(code, "/fc/dispatch"). To end a revoked worker’s push streams from the same
handler: pushes.endStreams(PushHolders.of(event)).
err := flowcatalyst.OnFieldRevocation(fc.Receivers(), func(ctx context.Context, cx fw.Context, e flowcatalyst.FieldRevocation) error { switch e := e.(type) { case flowcatalyst.WorkerSuspended: // e.WorkerID, e.ClientID case flowcatalyst.DeviceRevoked: // e.DeviceID, e.ClientID case flowcatalyst.SessionRevoked: // e.SessionID, e.WorkerID, e.DeviceID, e.ClientID, e.Reason } return nil // an error is a transient failure: the platform delivers again})Declare the subscription with Definitions.Subscription. To end the worker’s push streams: pushes.EndStreams(ctx, flowcatalyst.PushHolder(e)).
SessionRevoked carries the login family (sessionId) only when one family was revoked (a refresh token presented
again). When an administrator revokes every session of a worker or a device, you get the worker or device id and no
session id.
Testing
Section titled “Testing”TestOidcProvider provider = TestOidcProvider.start(clock);TestFieldDevice device = TestFieldDevice.create(clock);String token = provider.fieldToken("orders", device.jkt(), Map.of()); // any claim can be overriddenString proof = device.proof("GET", "https://app.example/api/me", nonce, token);client.get("/api/me").header("Authorization", "DPoP " + token).header("DPoP", proof).send();TestFieldDevice.proof(...) is valid unless you pass a Flaw (OTHER_DEVICE_KEY, BAD_SIGNATURE, WRONG_METHOD,
WRONG_URL, WRONG_ATH, STALE, NO_JTI, NO_NONCE, WRONG_TYP, WRONG_ALG, PRIVATE_MEMBER). To get a nonce as
a device does, send without one and read DPoP-Nonce from the 401 (TestFieldDevice.nonceFrom).
AuthTesting.of(app).fieldRequest(worker, device, provider::signField, "POST", "/api/things") returns the
Authorization and DPoP headers. Like all of AuthTesting it is refused unless APP_ENV is test.
tt, _ := module.Testing()device := authtest.NewFieldDevice(authtest.DeviceClock(clock))provider.FieldAudience("orders")headers, _ := tt.FieldRequest(provider, device, "POST", "/api/echo", auth.FieldPrincipal{DeviceMode: "SHARED"})// headers carry Authorization and DPoP; zero FieldPrincipal fields get defaultsauthtest.Provider.FieldToken(claims) mints a field access token (RS256, ten minutes), any claim overridable (a nil
removes it); FieldTokenFor(device, claims) also binds it to a device. A device’s Proof(method, url, nonce, token, opts...) takes options that break one rule each (ProofHTM, ProofHTU, ProofATH, ProofJTI, ProofIssuedAt,
ProofWithoutNonce, ProofWithoutJTI, ProofSignedBy(other), ProofTamperedSignature, …). Testing.FieldNonce()
returns a current nonce, and authtest.NonceFrom(header) reads the DPoP-Nonce of a response.
The platform’s own conformance vectors (conformance/field/) run in both implementations.
Limits
Section titled “Limits”- No field login, PIN, enrolment or refresh happens here: those are the platform and the field libraries.
- Field pages are pages the field library calls with
fetch. No field cookie exists, and server-rendered field pages are not a thing. - Not checked: a request from a real field client library, and a real platform delivering the revocation events.