ruLog in to Senler

Backend Authorization

Prepare the Handler

Authorization is required for application actions. First, describe the allowed operations in OpenAPI.

How The Application Backend Is Authorized

An MCP key or OAuth token authorizes the AI client only with Senler. Senler checks the project, current permissions, active installation, and exact action published in OpenAPI. The original MCP secret, OAuth token, and authorization header are never forwarded to the plugin backend.

Instead, every management action call creates a short session between Senler and the application:

  1. Senler signs a one-time launch_code containing the project ID, expiry, and nonce with the application's Client Secret;
  2. it sends the code to /api/embedded/management-session on the same origin that hosts OpenAPI;
  3. the backend verifies the signature, expiry, and nonce replay, then returns its own short-lived management_token;
  4. Senler calls the marked endpoint with Authorization: Bearer <management_token>.

The session request looks like this:

POST /api/embedded/management-session
Content-Type: application/json

{"launch_code":"<one-time Senler code>"}

The application backend must verify launch_code using Client Secret and return its own short-lived token:

{"management_token":"app-session-token"}

Creating a management session must complete within 5 seconds, and the token response is limited to 64 KiB. An action has a 15-second timeout; its response is limited to 5 MiB, or 2 MiB for a funnel report. Redirects are not followed. Determine the project and permissions only from the verified management session, not from parameters supplied by AI.

The management_token is valid only in the application's own backend. If that backend then calls the Senler API, it needs its own API key or application OAuth access token with the required permissions. Neither the management_token nor the original MCP token is a Senler API credential for the plugin.

Landing visitor requests

Landing visitors do not receive a management session. For a regular button, Senler calls the registered POST with JSON {configuration, input}, the x-senler-landing-context header, and Idempotency-Key. The visitor handler must accept only this separate authorization.

The header value is <payloadBase64url>.<signatureBase64url>. The signature is HMAC-SHA256 of the payloadBase64url string, keyed with the app Client Secret. Compare the signature in constant time, then decode the payload and verify:

  • version === 1, purpose === "landing_action", and audience matches your app's OAuth Client ID;
  • expires_at has not passed; Senler issues signatures for 60 seconds;
  • method_name matches the registered action (landing__<key>);
  • body_sha256 matches SHA-256 of the original body bytes, before JSON parsing;
  • project_id and installation_id identify an active installation of your app.

The payload also contains landing_id, publication_id, binding_id, visitor_id, operation_id, and identity. visitor_id is a browser identifier, not proof of identity. identity is null or contains Senler-verified channel_id, platform, and external_user_id. An arbitrary user ID from input cannot replace this verification. The context authorizes only the declared visitor action, not project management.

Idempotency-Key is the hex SHA-256 of JSON.stringify([project_id, installation_id, landing_id, publication_id, binding_id, visitor_id, identity, operation_id]), in that order. Verify it against signed fields. Persist the operation result durably before successfully responding. Repeating the same key and body must return the stored result; reject a different body for an existing key. Check signature and expiry on every retry: Senler creates a fresh signature while preserving the key.

A timeout does not cancel an action. Never restart a paid or irreversible operation merely because its response was lost. If processing exceeds 15 seconds, accept it durably and return an accepted state; the app owns its asynchronous processing and subsequent result display.

Visitor authorization for an iframe block

A block does not register a handler URL. Its frontend requests bridge.getLandingAuthorization(), then sends the returned authorization to its own backend. This uses the same <payloadBase64url>.<signatureBase64url> format, with HMAC-SHA256 of payloadBase64url keyed with the app Client Secret. The secret stays on the servers.

The backend verifies the signature in constant time, version === 1, purpose === "landing_block", its Client ID in audience, the block key in method_name (landing__<key>), and the expires_at deadline. The proof lasts 60 seconds. It contains project_id, installation_id, landing_id, publication_id, binding_id, visitor_id, identity, and configuration. Use this signed configuration for backend operations, not a separate field in the browser request. Operations on behalf of a person require a non-null verified identity.

The app defines form data, request URLs, response formats, and request rate limits. The proof does not sign the body of this direct request: the backend validates user input and permits only operations available to this block's visitor. It grants no project management rights and is not accepted by a button handler requiring purpose: "landing_action".

A fresh proof can be requested before each call. For retries of one mutation, preserve its operation ID and original input; refreshing a signature does not create a new operation. The backend deduplicates using that ID together with signed project, installation, binding, and visitor identifiers. Disabling a block or republishing prevents new proofs from being issued; an existing proof remains valid until its expires_at.