Skip to content

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:

CallerCredential at /graphqlBest fitTrade-off
Same-origin browser UIidentity_flow_session cookie from OIDC sign-inProduction custom UIs hosted under a free prefix such as /app/ on IdentityFlow’s originLowest 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 /graphqlProduction backends that only act while a signed-in person is interacting with a web UIKeeps browser OIDC sign-in and session expiry intact; cannot run offline jobs after the session expires (at most 8 hours).
Opt-in unauthenticated service accessConfigured subject header (X-Workforce-Id by default), no cookie, no OriginIsolated cluster onboarding, internal service automation, or testing behind strict ingress strippingNo 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"]
}
  • serviceName identifies the calling service in startup warnings and audit evidence (initiatedBy.serviceName).
  • origin defaults to auth.oidc.origin and must be mapped to a registered provider in identity.originProviders.
  • headers.subject defaults to X-Workforce-Id. Optional headers.name and headers.email must be distinct valid HTTP header names (case-insensitively).
  • When enabled = true, IdentityFlow logs a WARN entry at startup naming the configured serviceName, subject header, origin, and allow groups, 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 optional name and email headers (or safe fallbacks). Later service calls never overwrite an existing account’s name or email.
  • Full fine-grained authorization: Every read and command resolves the person’s current principals through the identity provider hook configured for origin and enforces the active Access Configuration, dialog assignees, and resource locks. If the provider hook fails, reads and commands fail closed.
  • Strict /graphql boundary:
    • A request carrying a valid identity_flow_session cookie uses the browser session and ignores service headers.
    • A request carrying an expired or invalid identity_flow_session cookie never falls back to service headers (UNAUTHENTICATED).
    • A request carrying any Origin header never enters the service-header path (UNAUTHENTICATED for same-origin Origin; HTTP 403 for cross-origin POST).
    • HTML routes, /auth/*, and /support-export/* ignore service headers completely.
  • Audit provenance: Events triggered through opt-in service access record initiatedBy: { kind: "unauthenticatedService", serviceName, authenticated: false } alongside actorAccountId for the named person. Browser sessions record initiatedBy: null. See Audit evidence.

Service requests are restricted to the groups configured in allow (default ["personal", "business"]):

allow groupPermitted GraphQL operations
personalstartCatalog, initiationHistory, assignedDialogs, participationHistory, startWorkflow, completeDialog
businessbusiness
operationsoperations, attention, deadLetters, pauseInstance, resumeInstance, terminateInstance, reassignDialog, replayDeadLetter
auditaudit

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.codeCause for a service clientWhat your service does
UNAUTHENTICATEDMissing, 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.
FORBIDDENEither 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_FOUNDThe 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:

Terminal window
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 }
}
JSON

Pass 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):

Terminal window
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"]
}
}
}
JSON

Query assignedDialogs as the assignee’s subject, then submit the decision with completeDialog:

Terminal window
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 }
}
JSON
Terminal window
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": "mutation CompleteDialog($input: CompleteDialogInput!) { completeDialog(input: $input) { dialogId instanceId status decidedAt } }",
"variables": {
"input": {
"dialogId": "AaDqEKWteMilkd1bo5asVQ",
"status": "COMPLETED",
"data": { "decision": "approved" }
}
}
}
JSON

GraphQL over HTTP needs no dedicated SDK in Go. Use net/http and encoding/json against the shipped schema file:

  1. Get the schema from the release archive. Production introspection is disabled. Use identity-flow-vX.Y.Z.graphql from your release archive for code generation or query validation.
  2. Construct each request with a context and without cookies or Origin. Use http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(body)), set Content-Type: application/json and your configured X-Workforce-Id header, leave Cookie and Origin unset, and use an http.Client with a bounded Timeout and Jar: nil so no cookie jar attaches stale session cookies.
  3. Check both HTTP status and errors[]. IdentityFlow returns HTTP 200 for GraphQL execution errors; decode { Data json.RawMessage, Errors []GraphQLError } and check len(resp.Errors) > 0 before using Data.
  4. Map IdentityFlow’s GraphQL scalars cleanly:
GraphQL scalarWire formatRecommended Go type
ID22-character base64url UUIDv7 stringstring
DateTimeISO 8601 / RFC 3339 timestamp stringtime.Time (or *time.Time for nullable fields such as dueAt)
JSONArbitrary JSON value (params, taskContext, data)json.RawMessage (decode into your workflow’s struct) or any
ConnectionCursorOpaque cursor string (pageInfo.endCursor)string (*string when nullable)
  1. 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 to 100 on top-level lists; 1–200 on business.find and audit.find detail connections) and pageInfo.endCursor.

Before enabling auth.dangerouslyAllowUnauthenticatedServiceAccess, make sure no external client can inject the configured headers:

  • Strip or reject X-Workforce-Id (plus any configured headers.name and headers.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).