Documents for @litert/jwt / CoreApis/Stringify / stringify
Function: stringify()
stringify(
options):string
Defined in: src/lib/CoreApis/Stringify.ts:81
Encode the provided JWT data into a signed JWT string.
This function is one of the core APIs for JWT operations, and also a low-level API for signing JWTs. It does encode JWTs by provided header and payload, without doing any other operations like setting default claims in the payload, validating the payload claims, etc.
The only default operations it will do is to set the typ and alg claims in the JWT header according to the provided signer, and sign the JWT using the provided signer.
Parameters
options
The options to use for stringification of the JWT.
Returns
string
The signed JWT string.
Example
ts
import * as LibJWT from '@litert/jwt';
const signer = new LibJWT.RsaJwaSigner({
privateKey: '-----BEGIN PRIVATE KEY-----\n...',
digestType: LibJWT.EDigestType.SHA256,
});
const token = LibJWT.stringify({
header: {
kid: 'my-key-id',
},
payload: { foo: 'bar' },
signer: signer,
});
console.log(token);