Call GraphQL from a service
This page shows how an isolated backend service calls IdentityFlow’s /graphql
endpoint without a browser OIDC session. For a browser UI running on
IdentityFlow’s own origin, see Build your own UI. Every
query root, mutation, and error code is listed in the
GraphQL API reference.
IdentityFlow has no bearer token or API key authentication for backend services. Choose between these three setups based on where your caller runs:
| Caller | Credential at /graphql | Best fit | Trade-off |
|---|---|---|---|
| Same-origin browser UI | identity_flow_session cookie from OIDC sign-in | Production custom UIs hosted under a free prefix such as /app/ on IdentityFlow’s origin | Lowest operational risk; no extra auth boundary. See Build your own UI. |
| Same-origin BFF (Backend for Frontend) | Incoming browser identity_flow_session cookie forwarded to /graphql | Production backends that only act while a signed-in person is interacting with a web UI | Keeps browser OIDC sign-in and session expiry intact; cannot run offline jobs after the session expires (at most 8 hours). |
| Opt-in unauthenticated service access | Configured subject header (X-Workforce-Id by default), no cookie, no Origin | Isolated cluster onboarding, internal service automation, or testing behind strict ingress stripping | No cryptographic service token; relies entirely on network isolation plus proxy/ingress header stripping. |
If your backend acts as a BFF behind the same reverse proxy on IdentityFlow’s
origin, forward the browser’s identity_flow_session cookie to /graphql
instead of enabling unauthenticated service access. Never log forwarded
session cookies, and omit or preserve the same-origin Origin header consistently
so cross-origin browser requests are still rejected.
Unauthenticated service access is disabled by default. To opt in for an
isolated backend service, configure
auth.dangerouslyAllowUnauthenticatedServiceAccess alongside the mandatory
auth.oidc block:
dangerouslyAllowUnauthenticatedServiceAccess { enabled = true serviceName = "order-service" # Defaults to auth.oidc.origin; must be mapped in identity.originProviders. origin = "acme-login" headers { subject = "X-Workforce-Id" name = "X-Workforce-Name" email = "X-Workforce-Email" } # Default: ["personal", "business"]. Add "operations" or "audit" only when needed. allow = ["personal", "business"]}serviceNameidentifies the calling service in startup warnings and audit evidence (initiatedBy.serviceName).origindefaults toauth.oidc.originand must be mapped to a registered provider inidentity.originProviders.headers.subjectdefaults toX-Workforce-Id. Optionalheaders.nameandheaders.emailmust be distinct valid HTTP header names (case-insensitively).- When
enabled = true, IdentityFlow logs aWARNentry at startup naming the configuredserviceName, subject header,origin, andallowgroups, and displays a persistent, non-dismissible warning banner on Attention (/attention), Operations (/analytics), and Failed work (/dead-letters) for signed-in operators.
Every configuration key and validation rule is listed in Unauthenticated service access.
Opt-in service access changes only how /graphql identifies the acting person.
Nothing else moves into HTTP headers:
- Insert-only account seeding: If no account exists yet for
(origin, subject), IdentityFlow creates one on the first call using the optionalnameandemailheaders (or safe fallbacks). Later service calls never overwrite an existing account’snameoremail. - Full fine-grained authorization: Every read and command resolves the
person’s current principals through the identity provider hook configured for
originand enforces the active Access Configuration, dialog assignees, and resource locks. If the provider hook fails, reads and commands fail closed. - Strict
/graphqlboundary:- A request carrying a valid
identity_flow_sessioncookie uses the browser session and ignores service headers. - A request carrying an expired or invalid
identity_flow_sessioncookie never falls back to service headers (UNAUTHENTICATED). - A request carrying any
Originheader never enters the service-header path (UNAUTHENTICATEDfor same-originOrigin; HTTP403for cross-originPOST). - HTML routes,
/auth/*, and/support-export/*ignore service headers completely.
- A request carrying a valid
- Audit provenance: Events triggered through opt-in service access record
initiatedBy: { kind: "unauthenticatedService", serviceName, authenticated: false }alongsideactorAccountIdfor the named person. Browser sessions recordinitiatedBy: null. See Audit evidence.
Service requests are restricted to the groups configured in allow (default
["personal", "business"]):
allow group | Permitted GraphQL operations |
|---|---|
personal | startCatalog, initiationHistory, assignedDialogs, participationHistory, startWorkflow, completeDialog |
business | business |
operations | operations, attention, deadLetters, pauseInstance, resumeInstance, terminateInstance, reassignDialog, replayDeadLetter |
audit | audit |
Support exports (/support-export/*) are always refused for service contexts.
When a service calls an operation outside its configured allow groups, the
Engine raises WF_SERVICE_OPERATION_FORBIDDEN before looking up any resource,
and /graphql returns HTTP 200 with extensions.code: "FORBIDDEN":
{ "errors": [ { "message": "Operation not permitted for this service access", "locations": [{ "line": 1, "column": 3 }], "path": ["operations"], "extensions": { "code": "FORBIDDEN" } } ], "data": null}Distinguish the three common refusal responses in your client:
extensions.code | Cause for a service client | What your service does |
|---|---|---|
UNAUTHENTICATED | Missing, blank, or invalid (> 255 characters or control characters) subject header; invalid optional name/email header; expired/invalid session cookie present; or Origin header present. | Verify your HTTP client sends X-Workforce-Id without cookies or Origin, and check the configured header names. |
FORBIDDEN | Either the operation is outside allow (Operation not permitted for this service access, Engine code WF_SERVICE_OPERATION_FORBIDDEN), or the person may see an instance but not operate it (Command not allowed). | Keep allow narrow; add "operations" or "audit" only when the service genuinely needs them. |
NOT_FOUND | The resource does not exist, or the named person lacks FGA permission on an allowed operation (such as startWorkflow or completeDialog). | Do not retry blindly; treat as missing or unauthorized for that person. |
For validation errors (BAD_USER_INPUT with extensions.issues), CONFLICT,
and LOCKED, see the GraphQL API reference and
Error codes.
Send POST /graphql with content-type: application/json, the configured
subject header, no session cookie, and no Origin header (GET /graphql is
also supported for read queries). Every request body below is checked against
the served GraphQL schema in CI.
Supply X-Workforce-Name and X-Workforce-Email if you want unknown accounts
to be seeded with a readable name and email on first call:
curl --fail-with-body --silent --show-error \ -X POST http://127.0.0.1:3000/graphql \ -H 'content-type: application/json' \ -H 'X-Workforce-Id: alice' \ -H 'X-Workforce-Name: Alice Example' \ -H 'X-Workforce-Email: alice@example.com' \ --data-binary @- <<'JSON'{ "query": "query StartCatalog($first: Int, $after: String) { startCatalog { list(first: $first, after: $after) { items { id name version releaseChannel label } pageInfo { hasNextPage endCursor } } } }", "variables": { "first": 50, "after": null }}JSONPass the id from startCatalog as input.workflow, the workflow’s validated
parameters in input.params, and optional input.recipients (provider subject
identifiers whose relationships govern visibility in authorization.ts):
curl --fail-with-body --silent --show-error \ -X POST http://127.0.0.1:3000/graphql \ -H 'content-type: application/json' \ -H 'X-Workforce-Id: alice' \ --data-binary @- <<'JSON'{ "query": "mutation StartWorkflow($input: StartWorkflowInput!) { startWorkflow(input: $input) { id workflowName workflowVersion status createdAt } }", "variables": { "input": { "workflow": "AaDqEKp7cACAAAAAAAAAKg", "params": { "days": 5 }, "recipients": ["bob"] } }}JSONQuery assignedDialogs as the assignee’s subject, then submit the decision with
completeDialog:
curl --fail-with-body --silent --show-error \ -X POST http://127.0.0.1:3000/graphql \ -H 'content-type: application/json' \ -H 'X-Workforce-Id: bob' \ --data-binary @- <<'JSON'{ "query": "query AssignedDialogs($first: Int, $after: String) { assignedDialogs { list(first: $first, after: $after) { items { id instanceId workflowName name message dueAt createdAt } pageInfo { hasNextPage endCursor } } } }", "variables": { "first": 50, "after": null }}JSONcurl --fail-with-body --silent --show-error \ -X POST http://127.0.0.1:3000/graphql \ -H 'content-type: application/json' \ -H 'X-Workforce-Id: bob' \ --data-binary @- <<'JSON'{ "query": "mutation CompleteDialog($input: CompleteDialogInput!) { completeDialog(input: $input) { dialogId instanceId status decidedAt } }", "variables": { "input": { "dialogId": "AaDqEKWteMilkd1bo5asVQ", "status": "COMPLETED", "data": { "decision": "approved" } } }}JSONGraphQL over HTTP needs no dedicated SDK in Go. Use net/http and
encoding/json against the shipped schema file:
- Get the schema from the release archive. Production introspection is
disabled. Use
identity-flow-vX.Y.Z.graphqlfrom your release archive for code generation or query validation. - Construct each request with a context and without cookies or
Origin. Usehttp.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(body)), setContent-Type: application/jsonand your configuredX-Workforce-Idheader, leaveCookieandOriginunset, and use anhttp.Clientwith a boundedTimeoutandJar: nilso no cookie jar attaches stale session cookies. - Check both HTTP status and
errors[]. IdentityFlow returns HTTP200for GraphQL execution errors; decode{ Data json.RawMessage, Errors []GraphQLError }and checklen(resp.Errors) > 0before usingData. - Map IdentityFlow’s GraphQL scalars cleanly:
| GraphQL scalar | Wire format | Recommended Go type |
|---|---|---|
ID | 22-character base64url UUIDv7 string | string |
DateTime | ISO 8601 / RFC 3339 timestamp string | time.Time (or *time.Time for nullable fields such as dueAt) |
JSON | Arbitrary JSON value (params, taskContext, data) | json.RawMessage (decode into your workflow’s struct) or any |
ConnectionCursor | Opaque cursor string (pageInfo.endCursor) | string (*string when nullable) |
- Respect query limits. Keep queries within the server’s limits (depth 20,
1,000 tokens, 15 aliases, 50 directives, calculated cost 5,000) and page with
first(up to100on top-level lists;1–200onbusiness.findandaudit.finddetail connections) andpageInfo.endCursor.
Before enabling auth.dangerouslyAllowUnauthenticatedServiceAccess, make sure
no external client can inject the configured headers:
- Strip or reject
X-Workforce-Id(plus any configuredheaders.nameandheaders.email) on every reverse proxy, API gateway, or Kubernetes Ingress that accepts browser or external traffic. - Restrict the internal port or Service endpoint so only trusted cluster workloads can reach IdentityFlow directly with those headers.
- Follow the reverse-proxy configuration and header-stripping rules in Reverse proxy, TLS, and service-header stripping (or Ingress, TLS, and service-header stripping on Kubernetes).