[**Documentation**](index.md) *** [Documentation](packages.md) / Vonage JWT # Vonage JWT SDK for Node.js ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vonage/vonage-node-sdk/ci.yml?branch=3.x) [![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk) ![Latest Release](https://img.shields.io/npm/v/@vonage/jwt?label=%40vonage%2Fjwt&style=flat-square) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md) [![License](https://img.shields.io/npm/l/@vonage/accounts?label=License&style=flat-square)][license] Vonage This is the Vonage JWT SDK for Node.js. This package helps create JWT tokens to use with [Vonage APIs](https://www.vonage.com/). For full API documentation refer to [developer.vonage.com](https://developer.vonage.com/). * [Installation](#installation) * [Usage](#usage) * [Testing](#testing) ## Installation ### With NPM ```bash npm install @vonage/jwt ``` ### With Yarn ```bash yarn add @vonage/jwt ``` ## Usage All you need to do is `require('@vonage/jwt')`, and use the returned object tocreate your own JWT token. ```js const { tokenGenerate } = require('@vonage/jwt'); const jwtToken = tokenGenerate(applicationId, privateKey, generatorOptions); ``` ### Parameters * `applicationId: string` - The Vonage Application Id. * `privateKey: string | Buffer` - The private key. * `generatorOptions: GeneratorOptions` - An object that can be used to set options for the token. See the [`jsonwebtoken`](https://www.npmjs.com/package/jsonwebtoken) for all options and claims. You can also pass in a Vonage [`acl`](https://developer.vonage.com/conversation/guides/jwt-acl) ## Testing Run: ```bash npm run test ``` [signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk [license]: _media/LICENSE.txt ## Classes ### InvalidApplicationIdError Defined in: [packages/jwt/lib/errors/invalidApplicationIdError.ts:9](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/invalidApplicationIdError.ts#L9) InvalidMissingApplicationIdError` class for throwing an error when the application id is not a valid string. You can get the application ID from your developer dashboard. The ID will be a UUID that was generated when you created the application. #### Extends - `Error` #### Constructors ##### Constructor ```ts new InvalidApplicationIdError(): InvalidApplicationIdError; ``` Defined in: [packages/jwt/lib/errors/invalidApplicationIdError.ts:10](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/invalidApplicationIdError.ts#L10) ###### Returns [`InvalidApplicationIdError`](#invalidapplicationiderror) ###### Overrides ```ts Error.constructor ``` #### Properties ##### cause? ```ts optional cause: unknown; ``` Defined in: node\_modules/typescript/lib/lib.es2022.error.d.ts:24 ###### Inherited from ```ts Error.cause ``` ##### message ```ts message: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1077 ###### Inherited from ```ts Error.message ``` ##### name ```ts name: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1076 ###### Inherited from ```ts Error.name ``` ##### stack? ```ts optional stack: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1078 ###### Inherited from ```ts Error.stack ``` ##### stackTraceLimit ```ts static stackTraceLimit: number; ``` Defined in: node\_modules/@types/node/globals.d.ts:161 The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. ###### Inherited from ```ts Error.stackTraceLimit ``` #### Methods ##### captureStackTrace() ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Defined in: node\_modules/@types/node/globals.d.ts:145 Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` ###### Parameters ###### targetObject `object` ###### constructorOpt? `Function` ###### Returns `void` ###### Inherited from ```ts Error.captureStackTrace ``` ##### prepareStackTrace() ```ts static prepareStackTrace(err, stackTraces): any; ``` Defined in: node\_modules/@types/node/globals.d.ts:149 ###### Parameters ###### err `Error` ###### stackTraces `CallSite`[] ###### Returns `any` ###### See https://v8.dev/docs/stack-trace-api#customizing-stack-traces ###### Inherited from ```ts Error.prepareStackTrace ``` *** ### InvalidPrivateKeyError Defined in: [packages/jwt/lib/errors/invalidPrivateKeyError.ts:10](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/invalidPrivateKeyError.ts#L10) `InvalidPrivateKeyError` class for throwing an error when the private key is invalid. The private key must either be the string of the key or a buffer from the key file. When you created the application, the private key would have been downloaded then. If you lost the key, you will need to regenrate the key. #### Extends - `Error` #### Constructors ##### Constructor ```ts new InvalidPrivateKeyError(): InvalidPrivateKeyError; ``` Defined in: [packages/jwt/lib/errors/invalidPrivateKeyError.ts:11](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/invalidPrivateKeyError.ts#L11) ###### Returns [`InvalidPrivateKeyError`](#invalidprivatekeyerror) ###### Overrides ```ts Error.constructor ``` #### Properties ##### cause? ```ts optional cause: unknown; ``` Defined in: node\_modules/typescript/lib/lib.es2022.error.d.ts:24 ###### Inherited from ```ts Error.cause ``` ##### message ```ts message: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1077 ###### Inherited from ```ts Error.message ``` ##### name ```ts name: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1076 ###### Inherited from ```ts Error.name ``` ##### stack? ```ts optional stack: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1078 ###### Inherited from ```ts Error.stack ``` ##### stackTraceLimit ```ts static stackTraceLimit: number; ``` Defined in: node\_modules/@types/node/globals.d.ts:161 The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. ###### Inherited from ```ts Error.stackTraceLimit ``` #### Methods ##### captureStackTrace() ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Defined in: node\_modules/@types/node/globals.d.ts:145 Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` ###### Parameters ###### targetObject `object` ###### constructorOpt? `Function` ###### Returns `void` ###### Inherited from ```ts Error.captureStackTrace ``` ##### prepareStackTrace() ```ts static prepareStackTrace(err, stackTraces): any; ``` Defined in: node\_modules/@types/node/globals.d.ts:149 ###### Parameters ###### err `Error` ###### stackTraces `CallSite`[] ###### Returns `any` ###### See https://v8.dev/docs/stack-trace-api#customizing-stack-traces ###### Inherited from ```ts Error.prepareStackTrace ``` *** ### MissingApplicationIdError Defined in: [packages/jwt/lib/errors/missingApplicationIdError.ts:9](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/missingApplicationIdError.ts#L9) `MissingApplicationIdError` class for throwing an error when the application id is missing. You can get the application ID from your developer dashboard. The ID will be a UUID that was generated when you created the application. #### Extends - `Error` #### Constructors ##### Constructor ```ts new MissingApplicationIdError(): MissingApplicationIdError; ``` Defined in: [packages/jwt/lib/errors/missingApplicationIdError.ts:10](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/missingApplicationIdError.ts#L10) ###### Returns [`MissingApplicationIdError`](#missingapplicationiderror) ###### Overrides ```ts Error.constructor ``` #### Properties ##### cause? ```ts optional cause: unknown; ``` Defined in: node\_modules/typescript/lib/lib.es2022.error.d.ts:24 ###### Inherited from ```ts Error.cause ``` ##### message ```ts message: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1077 ###### Inherited from ```ts Error.message ``` ##### name ```ts name: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1076 ###### Inherited from ```ts Error.name ``` ##### stack? ```ts optional stack: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1078 ###### Inherited from ```ts Error.stack ``` ##### stackTraceLimit ```ts static stackTraceLimit: number; ``` Defined in: node\_modules/@types/node/globals.d.ts:161 The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. ###### Inherited from ```ts Error.stackTraceLimit ``` #### Methods ##### captureStackTrace() ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Defined in: node\_modules/@types/node/globals.d.ts:145 Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` ###### Parameters ###### targetObject `object` ###### constructorOpt? `Function` ###### Returns `void` ###### Inherited from ```ts Error.captureStackTrace ``` ##### prepareStackTrace() ```ts static prepareStackTrace(err, stackTraces): any; ``` Defined in: node\_modules/@types/node/globals.d.ts:149 ###### Parameters ###### err `Error` ###### stackTraces `CallSite`[] ###### Returns `any` ###### See https://v8.dev/docs/stack-trace-api#customizing-stack-traces ###### Inherited from ```ts Error.prepareStackTrace ``` *** ### MissingPrivateKeyError Defined in: [packages/jwt/lib/errors/missingPrivateKeyError.ts:10](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/missingPrivateKeyError.ts#L10) `MissingPrivateKeyError` class for throwing an error when the private key is missing. The private key must either be the string of the key or a buffer from the key file. When you created the application, the private key would have been downloaded then. If you lost the key, you will need to regenrate the key. #### Extends - `Error` #### Constructors ##### Constructor ```ts new MissingPrivateKeyError(): MissingPrivateKeyError; ``` Defined in: [packages/jwt/lib/errors/missingPrivateKeyError.ts:11](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/errors/missingPrivateKeyError.ts#L11) ###### Returns [`MissingPrivateKeyError`](#missingprivatekeyerror) ###### Overrides ```ts Error.constructor ``` #### Properties ##### cause? ```ts optional cause: unknown; ``` Defined in: node\_modules/typescript/lib/lib.es2022.error.d.ts:24 ###### Inherited from ```ts Error.cause ``` ##### message ```ts message: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1077 ###### Inherited from ```ts Error.message ``` ##### name ```ts name: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1076 ###### Inherited from ```ts Error.name ``` ##### stack? ```ts optional stack: string; ``` Defined in: node\_modules/typescript/lib/lib.es5.d.ts:1078 ###### Inherited from ```ts Error.stack ``` ##### stackTraceLimit ```ts static stackTraceLimit: number; ``` Defined in: node\_modules/@types/node/globals.d.ts:161 The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured _after_ the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. ###### Inherited from ```ts Error.stackTraceLimit ``` #### Methods ##### captureStackTrace() ```ts static captureStackTrace(targetObject, constructorOpt?): void; ``` Defined in: node\_modules/@types/node/globals.d.ts:145 Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. ```js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` ``` The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`. The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace. The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance: ```js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a(); ``` ###### Parameters ###### targetObject `object` ###### constructorOpt? `Function` ###### Returns `void` ###### Inherited from ```ts Error.captureStackTrace ``` ##### prepareStackTrace() ```ts static prepareStackTrace(err, stackTraces): any; ``` Defined in: node\_modules/@types/node/globals.d.ts:149 ###### Parameters ###### err `Error` ###### stackTraces `CallSite`[] ###### Returns `any` ###### See https://v8.dev/docs/stack-trace-api#customizing-stack-traces ###### Inherited from ```ts Error.prepareStackTrace ``` ## Type Aliases ### ACL ```ts type ACL = object; ``` Defined in: [packages/jwt/lib/types/acl.ts:19](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/acl.ts#L19) Represents an Access Control List (ACL) with rules for different paths. #### Properties ##### paths ```ts paths: Record; ``` Defined in: [packages/jwt/lib/types/acl.ts:23](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/acl.ts#L23) Rules associated with different paths. *** ### ACLRule ```ts type ACLRule = object; ``` Defined in: [packages/jwt/lib/types/acl.ts:4](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/acl.ts#L4) Represents a rule for Access Control List (ACL). #### Properties ##### filters? ```ts optional filters: Record; ``` Defined in: [packages/jwt/lib/types/acl.ts:13](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/acl.ts#L13) Filters associated with this rule for more fine-grained control. ##### methods? ```ts optional methods: ("POST" | "PUT" | "PATCH" | "GET" | "DELETE")[]; ``` Defined in: [packages/jwt/lib/types/acl.ts:8](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/acl.ts#L8) An array of HTTP methods allowed by this rule. *** ### Claims ```ts type Claims = object; ``` Defined in: [packages/jwt/lib/types/claims.ts:8](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L8) JWT claims. #### See [https://developer.vonage.com/en/getting-started/concepts/authentication#claims](https://developer.vonage.com/en/getting-started/concepts/authentication#claims) #### Properties ##### acl? ```ts optional acl: ACL; ``` Defined in: [packages/jwt/lib/types/claims.ts:33](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L33) Access Control List claim, provides access control information. ##### application\_id? ```ts optional application_id: string; ``` Defined in: [packages/jwt/lib/types/claims.ts:44](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L44) Application ID claim, identifies the application that is the subject of the JWT. ##### exp? ```ts optional exp: number; ``` Defined in: [packages/jwt/lib/types/claims.ts:12](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L12) Expiration time of the JWT. ##### iat? ```ts optional iat: number; ``` Defined in: [packages/jwt/lib/types/claims.ts:38](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L38) Issued At claim, identifies the time at which the JWT was issued. ##### jti? ```ts optional jti: string; ``` Defined in: [packages/jwt/lib/types/claims.ts:22](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L22) JWT ID claim, provides a unique identifier for the JWT. ##### nbf? ```ts optional nbf: number; ``` Defined in: [packages/jwt/lib/types/claims.ts:28](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L28) Not Before claim, identifies the time before which the JWT must not be accepted for processing. ##### sub? ```ts optional sub: string; ``` Defined in: [packages/jwt/lib/types/claims.ts:17](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/claims.ts#L17) Subject claim, identifies the principal that is the subject of the JWT. *** ### GeneratorOptions ```ts type GeneratorOptions = object; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:6](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L6) Claims to pass in for the token generator. #### Indexable ```ts [key: string]: unknown ``` Additional custom properties and values. #### Properties ##### acl? ```ts optional acl: ACL; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:35](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L35) Access control list. ##### exp? ```ts optional exp: number; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:47](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L47) The time at which the JWT expires. If set to a time less than issued_at, the token will expire in 15 minutes. ##### issued\_at? ```ts optional issued_at: number; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:15](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L15) The time at which the JWT was issued. ##### jti? ```ts optional jti: string; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:25](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L25) JSON Web Token ID. ##### key? ```ts optional key: string; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:40](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L40) Additional properties and values. ##### notBefore? ```ts optional notBefore: number; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:30](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L30) The time before which the JWT is not yet valid. ##### subject? ```ts optional subject: string; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:20](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L20) Subject of the token. ##### ttl? ```ts optional ttl: number; ``` Defined in: [packages/jwt/lib/types/generatorOptions.ts:10](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/types/generatorOptions.ts#L10) Time to live in seconds. ## Functions ### tokenGenerate() ```ts function tokenGenerate( applicationId, privateKey, opts?): string; ``` Defined in: [packages/jwt/lib/tokenGenerate.ts:87](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/tokenGenerate.ts#L87) Generates a JWT token. #### Parameters ##### applicationId `string` The application id. ##### privateKey The private key as a string or buffer. `string` | `Buffer` ##### opts? [`GeneratorOptions`](#generatoroptions) Optional generator options. #### Returns `string` - Returns the signed JWT token. #### Throws Throws an error if applicationId is missing. #### Throws Throws an error if privateKey is missing. #### Throws Throws an error if applicationId is not a string. #### Throws Throws an error if privateKey is not a string or buffer. #### See [https://developer.vonage.com/en/getting-started/concepts/authentication#json-web-tokens](https://developer.vonage.com/en/getting-started/concepts/authentication#json-web-tokens) #### Examples Generate a JWT token with default claims. ```js const privateKey = fs.readFileSync(__dirname + '/private.key'); const token = tokenGenerate(applicationId, privateKey); ``` Generate a JWT token with custom claims. ```js const privateKey = fs.readFileSync(__dirname + '/private.key'); const token = tokenGenerate(applicationId, privateKey, { subject: 'my-subject', acl: { paths: { '/*/users/**': {}, '/*/conversations/**': {}, '/*/sessions/**': {}, }, }, }); ``` *** ### verifySignature() ```ts function verifySignature(jwt, privateKey): boolean; ``` Defined in: [packages/jwt/lib/verifySignature.ts:34](https://github.com/Vonage/vonage-node-sdk/blob/3846dd78a7cd39b838839d5c93db0b1652c0d168/packages/jwt/lib/verifySignature.ts#L34) Verifies a JWT token #### Parameters ##### jwt `string` The JSON Web Token to verify. ##### privateKey The private key used to verify the JWT signature. `string` | `Buffer` #### Returns `boolean` Returns true if the JWT signature is verified successfully, otherwise returns false. #### Throws Throws an error if the private key is missing. #### Throws Throws an error if the private key is not a string or buffer. #### Example Validate a JWT token ```js const privateKey = fs.readFileSync('./private.key'); if (verifySignature(token, privateKey)) { console.log('JWT signature verified.'); } else { console.log('JWT signature verification failed.'); } ```