debugToken

View as MarkdownOpen in Claude

Decode token components for inspection without validating the signature. Useful for debugging token contents and checking expiration.

debugToken returns diagnostic data only when debugMode is true. With debugMode: false (the default), it returns { valid_format: false, error: "debug mode not enabled" } — matching the Python SDK’s behavior. Enable debugMode at runtime only when you need to inspect tokens.

Parameters

token
stringRequired

The base64url-encoded token to decode.

Returns

DebugTokenResult — a nested object with the following optional fields:

valid_format
boolean

true when the token decoded into five dot-separated parts; false otherwise.

components
object

Present only when valid_format is true.

components.call_id
string

Call ID extracted from the token. Truncated to 8 characters followed by ... when longer than 8 characters.

components.function
string

Function name encoded in the token.

components.expiry
string

Token expiry as a Unix timestamp string.

components.expiry_date
string | null

ISO 8601 string representation of the expiry, or null when the expiry component did not parse as a number.

components.nonce
string

The random nonce component of the token.

components.signature
string

Token signature. Truncated to 8 characters followed by ... when longer than 8 characters.

status
object

Present only when valid_format is true.

status.current_time
number

Current Unix timestamp in seconds.

status.is_expired
boolean | null

true if expired, false if still valid, null if the expiry component did not parse.

status.expires_in_seconds
number | null

Seconds remaining until expiry, or 0 when expired, or null when expiry did not parse.

parts_count
number

Only populated when valid_format is false because the decoded token had an unexpected number of dot-separated parts.

token_length
number

Length of the raw token string. Populated when valid_format is false.

error
string

Set to "debug mode not enabled" when debugMode is false, or to the caught error message when decoding failed.

Example

1import { SessionManager } from '@signalwire/sdk';
2
3const sm = new SessionManager();
4sm.debugMode = true; // enable before calling debugToken
5const token = sm.generateToken('get_weather', 'call-abc123');
6const info = sm.debugToken(token);
7
8if (info.valid_format) {
9 console.log('Function:', info.components!.function);
10 console.log('Expired:', info.status!.is_expired);
11} else {
12 console.log('Error:', info.error);
13}