From f43008d541b0e6799dd08dca671cfdcd19e79476 Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Thu, 29 Aug 2024 13:54:02 +0200 Subject: [PATCH] add new token generator syntax for JS --- .../docusaurus/docs/api/_common_/rtmp.mdx | 2 +- .../docs/api/basics/authentication.mdx | 47 ++++++++++++++----- .../docs/api/basics/get_started.mdx | 6 +-- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx b/docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx index 0f4dd543..e113ced2 100644 --- a/docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx +++ b/docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx @@ -10,7 +10,7 @@ const resp = await call.get(); // userId of existing user const userId = 'jane'; await client.upsertUsers([{ id: userId }]); -const token = client.createToken(userId); +const token = client.generateUserToken({ user_id: userId }); const rtmpURL = resp.call.ingress.rtmp.address; const streamKey = token; diff --git a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx index 48bfc10e..8085f735 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx @@ -93,11 +93,6 @@ await client.upsertUsers({ [newUser.id]: newUser, }, }); - -// exp is optional (by default the token is valid for an hour) -const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; - -client.createToken(userId, exp); ``` @@ -277,9 +272,9 @@ You can optionally provide an expiration time. By default, tokens are valid for ```js const userId = 'john'; -// exp is optional (by default the token is valid for an hour) -const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; -client.createToken(userId, exp); +// validity is optional (by default the token is valid for an hour) +const validity = 60 * 60; +client.generateUserToken({ user_id: userId, validity_in_seconds: validity }); ``` @@ -325,6 +320,16 @@ SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} echo "${HEADER}.${PAYLOAD}.${SIGNATURE}" ``` + + + +```js +const userId = 'john'; +// exp is optional (by default the token is valid for an hour) +const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; +client.createToken(userId, exp); +``` + @@ -340,16 +345,16 @@ Call tokens contain a list of call IDs. When a user utilizes a call token, they ```js -const userId = 'john'; -// exp is optional (by default the token is valid for an hour) -const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; +const user_id = 'john'; +// validity is optional (by default the token is valid for an hour) +const validity_in_seconds = 60 * 60; const call_cids = ['default:call1', 'livestream:call2']; -client.createCallToken(userId, call_cids, exp); +client.generateCallToken({ user_id, call_cids, validity_in_seconds }); // Optionally provide a role for the call(s) -client.createCallToken({ user_id: userId, role: 'admin' }, call_cids); +client.generateCallToken({ user_id, call_cids, role: 'admin' }); ``` @@ -386,5 +391,21 @@ SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET} echo "${HEADER}.${PAYLOAD}.${SIGNATURE}" ``` + + + +```js +const userId = 'john'; +// exp is optional (by default the token is valid for an hour) +const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; + +const call_cids = ['default:call1', 'livestream:call2']; + +client.createCallToken(userId, call_cids, exp); + +// Optionally provide a role for the call(s) +client.createCallToken({ user_id: userId, role: 'admin' }, call_cids); +``` + diff --git a/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx b/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx index cf68ef42..d7e67eac 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/get_started.mdx @@ -126,10 +126,10 @@ const newUser: UserRequest = { }; await client.upsertUsers([newUser]); -// exp is optional (by default the token is valid for an hour) -const exp = Math.round(new Date().getTime() / 1000) + 60 * 60; +// validity is optional (by default the token is valid for an hour) +const vailidity = 60 * 60; -client.createToken(userId, exp); +client.generateUserToken({ user_id: userId, validity_in_seconds: validity }); ```