Skip to main content
Embed Firma’s template editor inside your application using JWT authentication for secure, time-limited access. This is ideal for white-label integrations and multi-tenant applications.

Use cases

  • White-label template editing: Let users edit templates under your brand
  • Multi-tenant applications: Secure per-user template access without exposing API keys
  • Embedded workflows: Seamless template creation within your product
  • Time-limited access: Tokens expire automatically for security

How it works

  1. Your server requests a JWT token from Firma’s API using your API key
  2. Firma returns a short-lived JWT token with the template ID
  3. Your frontend embeds the editor with the JWT token
  4. The token expires automatically (configurable expiration)
Rate limit: JWT endpoints support 120 requests per minute per API key for high-volume applications.

JWT Authentication

Generate JWT token

Generate a JWT token for a specific template using the /generate-template-token endpoint. Endpoint: POST /generate-template-token Request body:
Response (201 Created):
Rate limit headers:

Implementation guide

Security: Never expose your API key in client-side code. Always generate JWT tokens from your secure backend.

Backend: Generate JWT token

Call the Firma API from your backend to generate a JWT token. Your backend endpoint should accept a template ID and return the JWT to your frontend. Node.js example:
Python example:

Frontend implementation — HTML / Vanilla JavaScript

Frontend implementation — React

Configuration Options

Instance Methods

Use triggerClose() when your host application needs to close the editor from its own UI — for example, a parent navigation event or a “back” button:

postMessage events (editor → host)

Firma’s editor will emit postMessage events for important lifecycle actions. Below is a recommended, minimal event schema you can implement for reacting to editor saves and publishes. If you have a canonical schema in your platform, replace these with your official event names.
Use these events to track editor activity without making additional API calls, helping you stay within rate limits.
Event envelope (window.postMessage payload):

Client listener example (plain JS)


Token lifecycle management

JWT tokens are generated with sufficient expiration time for typical editing sessions. The editor will automatically handle token expiration.

Automatic expiration

JWT tokens expire automatically based on the expires_at timestamp. After expiration:
  • The embedded editor will reject the token
  • Users must request a new token to continue
  • No API call needed — tokens expire passively

Rate limiting

See the guide on Rate Limits.

Security best practices

Never expose your API key in client-side code. Always generate JWT tokens from a secure server endpoint.

✅ Do’s

  • ✅ Generate tokens from your backend server
  • ✅ Monitor rate limits
  • ✅ Use HTTPS for all API requests

❌ Don’ts

  • ❌ Don’t expose API keys in frontend code
  • ❌ Don’t reuse tokens across users
  • ❌ Don’t log JWT tokens (security risk)
  • ❌ Don’t share tokens between different templates

Troubleshooting

Token expired error

Symptom: Editor shows “Token expired” or authentication error Solution:
  • Implement token refresh before expiration
  • Generate a new token and reload the iframe
  • Check system clock synchronization

401 Unauthorized

Symptom: JWT generation fails with 401 Possible causes:
  • Invalid or missing API key
  • API key doesn’t have required permissions
  • API key is disabled
Solution: Verify API key in dashboard and check permissions

404 Not Found

Symptom: Template not found when generating JWT Possible causes:
  • Template ID doesn’t exist
  • Template belongs to different workspace
  • Template was deleted
Solution: Verify template ID and workspace access

Rate limit exceeded

Symptom: 429 Too Many Requests Solution:
  • Implement token caching
  • Increase token expiration time
  • Wait for rate limit reset (check X-RateLimit-Reset header)
  • Implement retry logic with backoff

Next steps