Expose audit logs to your customers using viewer tokens, tenant isolation, and embeddable components.
Multi-tenant SaaS applications often need to show customers their own activity history — who on their team did what and when. Immutable’s viewer tokens let you securely expose a read-only, tenant-scoped view of the audit log without giving customers access to your API key or other tenants’ data.
import { ImmutableClient } from "getimmutable";const client = new ImmutableClient({ apiKey: "imk_sk_a1b2c3d4e5f6g7h8i9j0", baseUrl: "https://getimmutable.dev",});// Scoped to the customer's organizationconst token = await client.createViewerToken({ tenantId: "org_acme_corp", ttl: 3600,});// Send token.viewer_token to your frontendconsole.log(token.viewer_token);// "vt_eyJhbGciOiJIUzI1NiIs..."
from getimmutable import ImmutableClientclient = ImmutableClient( api_key="imk_sk_a1b2c3d4e5f6g7h8i9j0", base_url="https://getimmutable.dev")token = client.create_viewer_token(tenant_id="org_acme_corp", ttl=3600)# Send token["viewer_token"] to your frontendprint(token["viewer_token"])
use GetImmutable\Laravel\Facades\AuditLog;// In your controller, generate a token for the authenticated user's org$token = AuditLog::createViewerToken([ 'tenant_id' => $request->user()->organization_id, 'ttl' => 3600,]);return response()->json(['viewer_token' => $token['viewer_token']]);
Viewer tokens are read-only and cannot be used to ingest events. They only grant access to events matching the scoped tenant_id (and optionally actor_id).
When building a custom activity feed, implement cursor-based pagination using the cursor parameter from the API response. This ensures you can load older events without missing any.
Even if a query doesn’t include tenant_id as a filter, the viewer token enforces it. A viewer token scoped to org_acme_corp can never see events from other tenants.