Skip to main content
View as Markdown

KS Fundamentals - Authentication

KS Fundamentals​

A Kaltura Session (KS) is a signed, time-limited token you attach to API calls and player embeds. KS can be USER (type=0) or ADMIN (type=2). Use USER for almost everything where an end-user is interacting with apps or data; use ADMIN only for trusted backend-only workflows with short TTLs and strict configurations (roles, privileges).

Common use-cases and considerations:

  • Server-to-server or trusted backend: session.start → returns a KS with the privileges and expiry you request. Run this server-side only to keep secrets secure.
  • App-to-API with elevated but scoped permissions: use Application Tokens and appToken.startSession. You obtain a basic (unprivileged) KS, compute a hash with the app token, and exchange it for a privileged KS — keeping admin secrets and hashing strictly server-side.
  • Widget/player bootstrap (the player will generate this KS by itself if no KS was provided to the player: session.startWidgetSession to get a base KS used in the App Token flow.

KS Internal Structure​

A KS is a base64-encoded string containing these components:

FieldDescription
Partner IDThe Kaltura account that issued the KS
User IDThe user identity bound to this session
Type0 = USER, 2 = ADMIN
ExpiryUnix timestamp when the KS becomes invalid
PrivilegesComma-separated privilege strings (e.g., sview:*,privacycontext:PORTAL)
Random numberPrevents replay of identical requests
KS dataAdditional session context (action limits, session ID)
SignatureSHA-1 hash of all fields above — tamper-proofing

KS v2 (current default) wraps the payload in AES-CBC encryption before base64 encoding, so the internal fields are not readable by inspecting the string. The server decrypts and validates on every request.

KS Validation Flow​

The server validates the KS on every API request in this sequence:

  1. Signature check — Verify the SHA-1 signature matches the decrypted payload
  2. Expiry check — Reject if the KS has expired (Unix timestamp comparison)
  3. Action limit — If actionslimit:N is set, decrement and reject if exhausted
  4. Revocation check — Check if session.end was called for this KS or its sessionid group
  5. Permission check — Verify the KS type and role grant access to the requested service/action
  6. Entitlement check — If entitlements are enabled, verify the user has category membership for the requested content
  7. Account check — Verify the partner ID is active and the service is enabled
  8. Set user context — Bind the validated userId to the request for ownership, analytics, and audit

If any step fails, the server returns a KalturaAPIException with the relevant error code (INVALID_KS, EXPIRED_KS, SERVICE_FORBIDDEN, etc.).

KS Creation Methods — Comparison​

MethodCredentials RequiredBest ForTrade-offs
session.startpartnerId + adminSecretBackend tools, server-side automationHTTP roundtrip; exposes admin secret (keep server-side only)
session.startWidgetSessionpartnerId only (no secret)Anonymous player bootstrap, AppToken base KSUnprivileged — read-only access to public content
appToken.startSessionappToken ID + HMAC hashProduction integrations, client-facing appsPreferred: no secrets exposed, revocable, scoped privileges
user.loginByLoginIdemail + passwordEnd-user self-authentication, mobile appsUser-managed credentials; requires user provisioning first