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.
npm install opentok-tokenVerified import paths — ran on the pinned version, not inferred.
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.
Manually ensure all `tokenData` properties conform to OpenTok's specifications for roles, expiry, and session IDs. For more robust handling and validation, consider using the official `opentok-node` SDK instead.
Evaluate your project's long-term stability and security needs. For new projects or critical applications, it is strongly recommended to use the actively maintained `opentok-node` SDK or a similar up-to-date solution.
For maximum compatibility, especially in older Node.js environments or mixed CJS/ESM projects, use the `require()` syntax: `const encodeToken = require('opentok-token');`.Double-check `apiKey`, `apiSecret`, and all `tokenData` properties (especially `session_id`, `role`, and `expire_time`) against OpenTok's API documentation. Ensure `connection_data` is a properly JSON-stringified string. Consider using `opentok-node` for automatic validation.
Ensure you are importing the default export correctly. For CommonJS, use `const encodeToken = require('opentok-token');`. For ESM, use `import encodeToken from 'opentok-token';` and ensure your Node.js environment or build setup properly handles CJS interoperability.No dependency data recorded yet.