Skip to content

Impersonation (X-On-Behalf-Of) #120

Description

@derpixler

API Reference: On Behalf Of

Two modes for API-level impersonation.

Block-based (preferred): $client->performOnBehalfOf($userId, fn() => ...) sets the X-On-Behalf-Of header before the callback and clears it in a finally block — guaranteed cleanup even if the callback throws. Use for single or batched operations where impersonation should be temporary.

Persistent: $client->setOnBehalfOfUser($id) sets the header globally — all subsequent requests carry it until unsetOnBehalfOfUser() is called. Use when an entire process runs as a specific user.

The header is injected by RequestHandler — if onBehalfOfUser is set, every request() call adds the header before sending.

Acceptance Criteria

  • Testing: ZammadClientTest — performOnBehalfOf() sets X-On-Behalf-Of header during callback, clears header in finally (even on exception)
  • Documentation in README: README — $client->performOnBehalfOf($id, fn) example

Depends on

Produces

  • ZammadClient (onBehalfOf methods)
  • RequestHandler (header injection)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions