JWS workup

node v8.17.0
version: 1.0.0
endpointsharetweet
Create a JWT - Signed.
Set up dependencies:
var jose = require("node-jose");
Generate a keyset, or use one. This is a PEM private key:
var pem = "-----BEGIN RSA PRIVATE KEY-----" + "MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw"+ "33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW"+ "+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB"+ "AoGAD+onAtVye4ic7VR7V50DF9bOnwRwNXrARcDhq9LWNRrRGElESYYTQ6EbatXS"+ "3MCyjjX2eMhu/aF5YhXBwkppwxg+EOmXeh+MzL7Zh284OuPbkglAaGhV9bb6/5Cp"+ "uGb1esyPbYW+Ty2PC0GSZfIXkXs76jXAu9TOBvD0ybc2YlkCQQDywg2R/7t3Q2OE"+ "2+yo382CLJdrlSLVROWKwb4tb2PjhY4XAwV8d1vy0RenxTB+K5Mu57uVSTHtrMK0"+ "GAtFr833AkEA6avx20OHo61Yela/4k5kQDtjEf1N0LfI+BcWZtxsS3jDM3i1Hp0K"+ "Su5rsCPb8acJo5RO26gGVrfAsDcIXKC+bQJAZZ2XIpsitLyPpuiMOvBbzPavd4gY"+ "6Z8KWrfYzJoI/Q9FuBo6rKwl4BFoToD7WIUS+hpkagwWiz+6zLoX1dbOZwJACmH5"+ "fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523"+ "Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP"+ "FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw=="+ "-----END RSA PRIVATE KEY-----";
Make this a Key, import the PEM:
var key = await jose.JWK.asKey(pem, "pem");
Create the Claim set:
var payload =JSON.stringify({"sub": "1234567890", "name": "Eric D.", "role": "admin","iat": 1516239022});
Get the signed token.
var token = await jose.JWS.createSign({alg: "RS256", format: 'compact'}, key).update(payload, "utf8").final();
Loading…

no comments

    sign in to comment