I'm trying to create a JSON web key set for use with a node.js API client. However when logging my keys they seem to be empty.
const {JWKS} = require("jose");
const keyAlg = "RSA";
const keySize = 2048;
const keyUse = "sig";
const alg = "RS256";
const keystore = new JWKS.KeyStore();
keystore.generate(keyAlg, keySize, {
alg,
use: keyUse,
});
console.log("Public keys");
console.log("This can be used as the jwks in your API client configuration in the portal");
console.log(JSON.stringify(keystore.toJWKS(), null, 4));
console.log("Private keys");
console.log("This can be used as the keys value when configuring the api client");
console.log(JSON.stringify(keystore.toJWKS(true), null, 4));
keystore.generate
is an asynchronous function. It returns a promise which won't be executed immediately. You can use.then
or async/await to get the results of a promise.Here is an example from the libraries github:
Applying this to your code:
If you are new to javascript asynchronous functions, take a look at the most popular question and answer on the topic: How do I return the response from an asynchronous call?