Signing keys and JWKS

Create an RSA key pair and publish the public half so Hub can verify your requests.

Hub has no client secret. Instead you sign your requests with a private key, and Hub checks the signature using a public key you publish.

This page shows you how to set that up.

How it works

  1. You create an RSA key pair
  2. You keep the private key secret and sign requests with it
  3. You publish the public key at a URL Hub can reach
  4. Hub fetches it and verifies your signature

Your private key never leaves your server. The public key can't be used to forge requests, so publishing it is safe.

Key requirements

AttributeValue
Key typeRSA
Size2048 bits
AlgorithmRS256
Usesig (signing, not encryption)

Step 1 — Create the key pair

📘

Use your organization's approved method

The example below uses openssl, so you can see each step. In practice, create the key with whatever method your organization has approved — for example a cryptography library in your application's language, your cloud provider's key management service, or a hardware security module (HSM). Any method works, as long as the key meets the requirements above.

# Private key - keep this secret
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out hub-private.pem

# Public key
openssl rsa -in hub-private.pem -pubout -out hub-public.pem
❗️

Store the private key the way you store any other production secret — a secrets manager or HSM. Never commit it, never log it, never send it to Interac.

Step 2 — Convert to JWK format

Your public key needs to be published as a JSON Web Key, not PEM. Each example reads hub-public.pem from Step 1 and writes jwks.json, ready to publish in Step 3.

import json
from jwcrypto import jwk  # pip install jwcrypto

with open("hub-public.pem", "rb") as f:
    key = jwk.JWK.from_pem(f.read())

public_key = key.export_public(as_dict=True)
public_key.update(use="sig", alg="RS256", kid=key.thumbprint())

with open("jwks.json", "w") as f:
    json.dump({"keys": [public_key]}, f, indent=2)
import { readFile, writeFile } from "node:fs/promises";
import { importSPKI, exportJWK, calculateJwkThumbprint } from "jose"; // npm install jose

const key = await importSPKI(await readFile("hub-public.pem", "utf8"), "RS256", { extractable: true });

const publicJwk = await exportJWK(key);
Object.assign(publicJwk, { use: "sig", alg: "RS256", kid: await calculateJwkThumbprint(publicJwk) });

await writeFile("jwks.json", JSON.stringify({ keys: [publicJwk] }, null, 2));
//DEPS com.nimbusds:nimbus-jose-jwt:10.10
//DEPS org.bouncycastle:bcpkix-jdk18on:1.87

import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.jwk.JWK;
import com.nimbusds.jose.jwk.JWKSet;
import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.RSAKey;
import java.nio.file.Files;
import java.nio.file.Path;

public class ToJwks {
    public static void main(String[] args) throws Exception {
        RSAKey key = JWK.parseFromPEMEncodedObjects(Files.readString(Path.of("hub-public.pem"))).toRSAKey();

        RSAKey publicKey = new RSAKey.Builder(key)
                .keyUse(KeyUse.SIGNATURE)
                .algorithm(JWSAlgorithm.RS256)
                .keyIDFromThumbprint()
                .build();

        Files.writeString(Path.of("jwks.json"), new JWKSet(publicKey).toString());
    }
}
#:package [email protected]
#:property PublishAot=false

using System.Security.Cryptography;
using System.Text.Json;
using Microsoft.IdentityModel.Tokens;

var rsa = RSA.Create();
rsa.ImportFromPem(File.ReadAllText("hub-public.pem"));

var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(new RsaSecurityKey(rsa.ExportParameters(false)));
var publicKey = new { kty = "RSA", n = jwk.N, e = jwk.E, use = "sig", alg = "RS256", kid = Base64UrlEncoder.Encode(jwk.ComputeJwkThumbprint()) };

File.WriteAllText("jwks.json", JsonSerializer.Serialize(new { keys = new[] { publicKey } }, new JsonSerializerOptions { WriteIndented = true }));

The kid is the key's thumbprint, a stable ID calculated from the key itself, so all four examples produce the same kid for the same key.

Prefer to create the key in code instead? The Create your signing key and JWKS recipe for each language does Steps 1 and 2 in one go.

Each key in the result has these properties:

{
  "kty": "RSA",
  "use": "sig",
  "alg": "RS256",
  "kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU",
  "n": "...",
  "e": "AQAB"
}
PropertyMeaning
ktyKey type — RSA
usesig
algRS256
kidKey ID — a unique name for this key
n, eThe key material
❗️

kid is required. You put the same value in the header of every JWT you sign, and it's how Hub knows which key to check against. Without it, verification fails.

Step 3 — Publish it

Host a JWKS document at an HTTPS URL. It's a JSON object with a keys array:

{
  "keys": [
    {
      "kty": "RSA",
      "use": "sig",
      "alg": "RS256",
      "kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU",
      "n": "...",
      "e": "AQAB"
    }
  ]
}

Requirements:

  • HTTPS, publicly reachable from the internet
  • Not behind a VPN, firewall or IP allowlist
  • Returns application/json
  • Stable — Hub fetches it when verifying requests

A common location is https://your-domain.com/.well-known/jwks.json, but any HTTPS URL works.

🚧

Reachable from the internet means reachable by Hub, not just by you. A URL that resolves on your corporate network but not publicly is the most common onboarding failure. Test it from a device outside your network.

Step 4 — Give the URL to your representative

You provide the URL, not the key. Hub fetches the key from it.

Using the key

You sign two things with the private key:

WhatWhenaud
Request objectStep 2The issuer from discovery
Client assertionStep 4The token_endpoint URL

Both need kid in the JOSE header:

{
  "alg": "RS256",
  "kid": "cIlDeR8D4RexrZmUdKhBxMsD2bMX4l87_5JrARh4VIU"
}
🚧

The aud value is different between those two. Using the wrong one is the most common cause of a rejected signature. See Troubleshooting.

Rotating keys

A JWKS document can hold more than one key, which is what makes rotation safe:

  1. Generate a new pair with a new kid
  2. Add the new public key to your JWKS, keeping the old one
  3. Start signing with the new private key
  4. Once nothing is signing with the old key, remove it

Because every JWT names its kid, both keys work during the overlap. Don't remove the old key immediately.

Common mistakes

ProblemCause
invalid_clientkid missing from the JWT header, or not matching any key in your JWKS
Works locally, fails in productionJWKS URL not reachable from the internet
Signature rejected after rotationOld key removed too soon, or kid not updated
Audience errorWrong aud for the call being made
Intermittent failuresJWKS URL is slow or unreliable

Checking your work

# Should return JSON containing your key
curl https://your-domain.com/.well-known/jwks.json

Confirm it has kty, use, alg and kid, and that the kid matches what you put in your JWT headers.

Next

Redirect URIs