Hello ,
I start using K6 3 days ago, I’m trying to make a signature to a JW token through the xk6-jose extension.
Json web key :
{
"kty": "EC",
"d": "mG7Sp0QJFcSPpvC0Jg-BPmOO4ALA4_cqlGaOvbg2ed0",
"crv": "P-256",
"kid": "kid",
"x": "kAlnOBtvNp-42ZJAdYUwQZZfYXt88ARVvjnhH_DWcLk",
"y": "2cDwDG2FXXGf5EA0F27WIdO6xA6WltYlPlpGGuxcOEs",
"alg": "ES256",
"use": "sign"
}
code
import {parse} from "k6/x/jose/jwk";
import {sign} from "k6/x/jose/jwt";
const file = open("private.json");
const pkey = JSON.stringify(JSON.parse(file));
export default function () {
// Define the header and payload for the JWT token
const header = {
"alg": "ES256",
"typ": "JWT",
"kid": "Kid",
};
const payload = {
"sub": "1234567890",
"name": "John Doe",
"iat": "1675951923",
"nbf": "1675951923",
"exp": "1896876621",
"client_id": "clientID",
"nonce": "nonce"
};
const privatekey= parse(pkey)
const token = sign(privatekey, payload, header);
console.log(token)
};
When running this code, it fails with `ERRO[0000] GoError: could not convert [PrivatekeyValue] to context.Context
Any solution as to how I should properly parse my Json private Key ?