Tutorial 1 of 6
Set up your key
Create the key pair your integration signs in with, and send NeuroTrax the public half.
Your integration proves who it is with a key pair, the way HL7 SMART Backend Services and Epic do it: you keep the private key on your server, and NeuroTrax holds the public one. No password or secret is shared, and nothing secret ever crosses the network. The same key lets your integration act for a clinician and open NeuroTrax for them.
The examples use a common library per language: PyJWT (pip install "pyjwt[crypto]" requests), jose (npm install jose), Microsoft.IdentityModel.JsonWebTokens for .NET, and Nimbus JOSE+JWT for Java.
1Create a key pair
Create an RSA key of at least 2048 bits (3072 is a good choice), or an EC key on curve P-384. Keep the private key on your server, as safe as any password: whoever holds it can sign in as your integration.
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out neurotrax-private.pem
openssl pkey -in neurotrax-private.pem -pubout -out neurotrax-public.pem
Then print the public key in the form NeuroTrax reads, with a name of your choosing, such as your company and the date. The examples call it acme-2026-10. You'll use this key name when you sign in.
import json
from cryptography.hazmat.primitives import serialization
from jwt.algorithms import RSAAlgorithm
with open("neurotrax-public.pem", "rb") as f:
public_key = serialization.load_pem_public_key(f.read())
jwk = json.loads(RSAAlgorithm.to_jwk(public_key))
jwk.update(kid="acme-2026-10", alg="RS384", use="sig")
print(json.dumps(jwk)) # send this to NeuroTrax
// Node.js 18 or later
import { readFile } from "node:fs/promises";
import { exportJWK, importSPKI } from "jose";
const publicKey = await importSPKI(await readFile("neurotrax-public.pem", "utf8"), "RS384");
const jwk = { ...(await exportJWK(publicKey)), kid: "acme-2026-10", alg: "RS384", use: "sig" };
console.log(JSON.stringify(jwk)); // send this to NeuroTrax
// .NET 8 or later; package Microsoft.IdentityModel.JsonWebTokens
using System.Security.Cryptography;
using System.Text.Json;
using Microsoft.IdentityModel.Tokens;
using var rsa = RSA.Create();
rsa.ImportFromPem(File.ReadAllText("neurotrax-public.pem"));
var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(new RsaSecurityKey(rsa.ExportParameters(false)));
Console.WriteLine(JsonSerializer.Serialize(new { kty = jwk.Kty, n = jwk.N, e = jwk.E, kid = "acme-2026-10", alg = "RS384", use = "sig" })); // send this to NeuroTrax
// Java 15 or later; library com.nimbusds:nimbus-jose-jwt
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.jwk.JWK;
import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.RSAKey;
import java.nio.file.Files;
import java.nio.file.Path;
var publicKey = (RSAKey) JWK.parseFromPEMEncodedObjects(Files.readString(Path.of("neurotrax-public.pem")));
var jwk = new RSAKey.Builder(publicKey).keyID("acme-2026-10").algorithm(JWSAlgorithm.RS384).keyUse(KeyUse.SIGNATURE).build();
System.out.println(jwk.toPublicJWK().toJSONString()); // send this to NeuroTrax
// Go 1.21 or later
package main
import (
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/json"
"encoding/pem"
"fmt"
"math/big"
"os"
)
func main() {
raw, err := os.ReadFile("neurotrax-public.pem")
if err != nil {
panic(err)
}
block, _ := pem.Decode(raw)
parsed, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
panic(err)
}
key := parsed.(*rsa.PublicKey)
b64 := base64.RawURLEncoding.EncodeToString
jwk, _ := json.Marshal(map[string]string{
"kty": "RSA", "n": b64(key.N.Bytes()), "e": b64(big.NewInt(int64(key.E)).Bytes()),
"kid": "acme-2026-10", "alg": "RS384", "use": "sig",
})
fmt.Println(string(jwk)) // send this to NeuroTrax
}
# Ruby 3 or later; gem install jwt
require "jwt"
public_key = OpenSSL::PKey::RSA.new(File.read("neurotrax-public.pem"))
jwk = JWT::JWK.new(public_key, kid: "acme-2026-10").export.merge(alg: "RS384", use: "sig")
puts jwk.to_json # send this to NeuroTrax
// Cargo.toml: rsa = "0.9", base64 = "0.22", serde_json = "1"
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use rsa::{pkcs8::DecodePublicKey, traits::PublicKeyParts, RsaPublicKey};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = RsaPublicKey::from_public_key_pem(&std::fs::read_to_string("neurotrax-public.pem")?)?;
let jwk = serde_json::json!({
"kty": "RSA",
"n": URL_SAFE_NO_PAD.encode(key.n().to_bytes_be()),
"e": URL_SAFE_NO_PAD.encode(key.e().to_bytes_be()),
"kid": "acme-2026-10", "alg": "RS384", "use": "sig",
});
println!("{jwk}"); // send this to NeuroTrax
Ok(())
}
2Send us your public key
Email what it printed to your NeuroTrax contact. It holds only the public key, so email is safe. If it has a "d" field, it holds the private key: don't send it. Never send the private key or the .pem file it came from.
Along with it, tell us which accounts your integration should work in and what it needs to do: enroll patients, order tests, read results, act for clinicians, or open NeuroTrax for them.
NeuroTrax then registers your integration with that key and sends you:
- your client ID, which goes in every pass you sign;
- the accounts your integration is granted, by number;
- its scopes: what it may do;
- test credentials, if you'd like to try things without touching live patients.
That's all you need for Your first call.
3Rotate your key
NeuroTrax holds up to two keys for your integration, so you can change keys without downtime: create a new key pair with a new name, send us its public key, switch your server to signing with it once we confirm, then ask us to remove the old one.
Rotate on a schedule that suits your security policy, and at once if a private key may have leaked: tell us, and we remove the old key straight away. Every token it was used for ends with it.