Skip to main content

Token refresh and session expiry

Receiving a new token​

The token is short-lived, and only LXP issues new tokens.

  1. Before expiry, LXP passes a new token by changing only the fragment of the iframe URL (#token=…&baseUrl=…).
  2. The content is not reloaded; a hashchange occurs inside it.
  3. The SDK uses the new token from the next call on and removes token from the address bar. It does not reload the material.

The SDK never asks the server to refresh the token. If you need to know when the token changes (e.g. for the video player), use sdk.onAccessTokenChange(listener).

Content that uses hash routing

When a new token arrives, the content's hash changes to the value LXP passed (after token is removed, e.g. #baseUrl=…). The SDK ignores hashchange events without a token, so the content only needs to treat those as its own.

  • Previews opened with a token on the edit page (#token=…&preview=1, even with versionId) also receive new tokens the same way.
  • Previews without a token (#preview=1, #edit=1) have no token to replace.

Session expiry​

The session ends if the token expires before a new token arrives, or if the server ends the session. In that case, the content only needs to tell the user to refresh.

const sdk = new EliceCDK({
onSessionExpired: () => {
alertBanner('학습 시간이 길어졌어요. 페이지를 새로고침해 주세요.');
},
});
  • When the session ends, sdk.isSessionExpired becomes true, and every call after that fails with session_expired.
  • A session that ended because the token ran out resumes if a new token arrives later.
  • If the token expires without a new token, the SDK also sends status (failed, reason: 'auth') to the embedding page (Loading status).
  • alert cannot be used inside onSessionExpired because of the sandbox. Show the notice inside the screen.

Cleanup​

When taking the content down, call sdk.dispose() to stop the expiry timer and receiving new tokens.