How to embed public key in JWK format in JWS / JWT header?

Tomasz Zwierzchoń
1 min readMar 6, 2019

--

It is easy with node-jose library when you know how to do it.
It took me some time to learn, because this information is missing in the documentation. Luckily it was in tests.

The missing example (creates a JWT with an embedded ‘jwk’):

// {input} is a String
// {key} is from jwk keystore
jose.JWS.createSign(
{
fields: {
typ: 'JWT',
},
format: 'compact',
opts: { protect: false },
},
{
key,
reference: 'jwk', // MISSING in documentation
},
).update(input, 'utf-8')
.final()
.then((result) => {
// {result} is a JSON object -- JWT using the JSON General Serialization
});

I hope I saved you some time.

--

--

Tomasz Zwierzchoń

Skilled team leader and trainer. I excel at translating between business and technical languages. I am well-versed in agile methodologies, BDD, and TDD.