{"library":"opentok-token","title":"OpenTok Token Encoder","description":"The `opentok-token` package is a low-level utility designed to generate `X-TB-TOKEN-AUTH` headers for authentication with the OpenTok REST API. As of its current stable version, 1.1.1, it focuses solely on the encoding process, transforming provided token data, an API key, and an API secret into a JWT string. A critical characteristic of this package is its explicit lack of input validation; it does not check if the provided data aligns with OpenTok REST API semantics, allowing for the generation of syntactically correct but functionally invalid tokens. It offers default values for `create_time`, `expire_time`, `role`, and `nonce` if these properties are omitted from the token data. Its primary distinction is its role as a simple encoder, contrasting with the more comprehensive `opentok-node` server SDK, which provides a full suite of API interactions including data validation. Given its last update several years ago, the package is effectively no longer maintained, indicating an inactive release cadence.","language":"javascript","status":"abandoned","last_verified":"Wed Apr 22","install":{"commands":["npm install opentok-token"],"cli":null},"imports":["import encodeToken from 'opentok-token';","const encodeToken = require('opentok-token');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const encodeToken = require('opentok-token');\n\n// IMPORTANT: Replace with your actual OpenTok API Key and Secret\nconst apiKey = process.env.OPENTOK_API_KEY ?? 'YOUR_API_KEY';\nconst apiSecret = process.env.OPENTOK_API_SECRET ?? 'YOUR_API_SECRET';\nconst sessionId = 'SESSIONID_FROM_OPENTOK'; // Replace with a valid OpenTok Session ID\n\n// Token data for a moderator role, expiring in 24 hours\nconst tokenData = {\n  session_id: sessionId,\n  // create_time and nonce will default to now and a random number if not specified\n  role: 'moderator',\n  // expire_time will default to now + 1 day if not specified\n  connection_data: JSON.stringify({ 'user_id': 'user123', 'level': 'gold' })\n};\n\ntry {\n  const token = encodeToken(tokenData, apiKey, apiSecret);\n  console.log('Generated OpenTok Token:', token);\n  // You would typically use this token in the X-TB-TOKEN-AUTH header\n  // when making requests to the OpenTok REST API.\n} catch (error) {\n  console.error('Error generating token:', error.message);\n}\n","lang":"javascript","description":"Demonstrates how to generate an OpenTok API token using `opentok-token`, including setting a role and connection data, with a note on required API credentials.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}