Authentication & Tokens
SmarterElements embeds are authenticated with short-lived, narrowly-scoped, revocable STS tokens issued by your backend through the SmarterServices Security Token Service (STS). Your long-lived API credential never reaches the browser — your server exchanges it for a token that is scoped to a single element, a single end user, and a short lifetime, then hands that token to the SDK.STS is a generic token service; SmarterElements embeds use the
element token type. Each issued
token is bounded by the permission ceiling of the credential that created it — a token can
never grant more than its creator already has.For general-purpose short-lived API access, STS also supports an
api token type with a
caller-supplied, ceiling-checked IAM policy. See STS Tokens for
both minting methods and their shared security guardrails.How it works
- The browser asks your backend for an embed (authenticated however you already authenticate your users).
- Your backend calls the STS endpoint using its own API credential and gets back a token set.
- Your backend returns the signed
elementToken(and optionally the runtimestsToken) to the browser. - The browser passes them to
elements.create(...); the SDK silently refreshes before expiry.
Issue a token
Call this from your backend (never the browser — it requires your API credential):Request body
The caller must hold the
sp:CreateStsToken action; the resulting token’s policy is validated as a subset of the caller’s effective policy before anything is minted.
Response 201
Pass the token to the SDK
Give the SDK the signedelementToken as elementToken, the opaque runtime credential as stsToken, and an onTokenRefresh callback that fetches a fresh token set from your backend. The SDK schedules a silent refresh before expiry (default at 80% of the TTL) and stops at absoluteExpiresAt.
Silent refresh
Long-lived embeds outlive a single 15-minute token, so the SDK rotates them automatically:- The SDK schedules a refresh at ~80% of the current token’s TTL (floored at 5s to avoid hot loops).
- Your
onTokenRefreshcallback calls the refresh endpoint and returns a new token set. - The new
stsToken(runtime credential) is forwarded to the element and atokenRefreshedevent fires (refresh rotates the credential; the signedelementTokenis issuance-only). - Once
absoluteExpiresAt(8h from the first token) is reached, refresh stops andtokenExpiredfires.
The SDK owns the scheduling and lifecycle — you don’t track expiry or wire up timers. But you
must supply the
onTokenRefresh callback: the STS refresh endpoint requires your API
credential, which must never live in the browser, so the callback bounces the refresh through your
backend. If you omit it, the token simply expires and the embed ends when the TTL runs out.Wire up the refresh callback
PassonTokenRefresh to elements.create(...). The SDK calls it shortly before expiry; it must fetch a fresh token set from your backend (which calls the STS refresh endpoint with your API credential) and return it:
onTokenRefresh return shape
The callback must resolve with an StsTokenSet containing:
Resolving with a valid set applies the new tokens and fires
tokenRefreshed. Throwing or returning a rejected promise fires tokenExpired and ends the session.
Refresh endpoint
previousSid field. The old credential is revoked once the replacement is minted. Refresh requires the sp:RefreshStsToken action and reuses the original token’s scoped policy — a refresh can never widen permissions or extend past the absolute session lifetime.
