ns_crypto::JWT method decode (public)

 <instance of ns_crypto::JWT[i]> decode token

Defined in

Decode a JSON Web Token (JWT) without performing signature verification. The method splits the token into its three components, decodes the protected header and payload from base64url, and parses them as JSON. The signature part is returned as raw binary data.

Parameters:
token (required)
JWT string in compact serialization format ("header.payload.signature").
Returns:
A Tcl dictionary with the following keys: header — parsed JWT header as Tcl dictionary payload — parsed JWT payload as Tcl dictionary signature — raw binary signature (empty for "alg=none")

Testcases:
No testcase defined.
Source code:
lassign [:split_token $token] headerB64 payloadB64 sigB64

set headerJson  [ns_base64urldecode -- $headerB64]
set payloadJson [ns_base64urldecode -- $payloadB64]

set header  [ns_json parse $headerJson]
set payload [ns_json parse $payloadJson]

return [dict create  header $header  payload $payload  signature [ns_base64urldecode -binary -- $sigB64]]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: