TheDocumentation Index
Fetch the complete documentation index at: https://docs.wisdom.ai/llms.txt
Use this file to discover all available pages before exploring further.
impersonateUser mutation exchanges a permanent access key for a short-lived JWT token that authenticates subsequent requests as a specific user. This is the core of the embedded session flow — the returned JWT is passed as the token query parameter in iframe embed URLs.
This mutation is public and unauthenticated — no Authorization header is required.
Signature
Parameters
Your permanent Descope access key. This is not a JWT or a prior session token — it is the long-lived key obtained from
support@askwisdom.ai. Must be kept secret and only used server-side.The email address of the user to impersonate. The user must already exist in Wisdom — call
createUsers first if needed.Optional key-value pairs applied only for this session. These override DATABASE-sourced attributes for the duration of the session and are not persisted. Useful for passing context that should not be stored on the user (e.g., a specific report context or request-scoped filter).See User Attributes for how attribute sources are prioritized.
Response
Returns a rawString! — the short-lived JWT to use as the token query parameter in iframe embed URLs. The token expires after 1 hour.
Usage example
Token lifecycle and refresh
| Property | Value |
|---|---|
| Lifetime | 1 hour |
| Refresh | Via postMessage (see below) |
| Priority | ?token= URL param always takes precedence over any cached token |
Built-in refresh via postMessage
WisdomAI sends a REQUEST_JWT_TOKEN event to the parent window approximately 10 seconds before the embedded token expires. It is the embedder’s responsibility to listen for this event, regenerate the token by calling impersonateUser from their backend, and post it back. WisdomAI then picks up the new token and continues the session seamlessly.
Flow:
- WisdomAI iframe detects the token is about to expire
- WisdomAI sends
window.parent.postMessage({ type: 'REQUEST_JWT_TOKEN' }, '*')to the host - Host receives the event and validates
event.originmatches the WisdomAI domain - Host calls
impersonateUservia its own backend to get a fresh JWT - Host posts back
iframe.contentWindow.postMessage({ type: 'JWT_TOKEN_RESPONSE', token }, WISDOM_ORIGIN) - WisdomAI receives the new token and refreshes the session
- WisdomAI sends with
'*'as target origin — the host must validateevent.originon its side - If the host does not respond within 10 seconds, the request times out and retries on the next render cycle
- Only one refresh request is in-flight at a time (duplicate requests are suppressed)
- The
?token=URL param always takes priority over any cached token
Related articles
Embed a Dashboard
Use the token in an iframe embed URL
Embed a Chat
Use the token for embedded chat
Create Users
Create users before impersonating them
User Attributes
Understand transient vs persistent attributes
Session Management
Full token lifecycle reference, including switching users