Developer Guide: Signed Context Injection
This guide explains how to generate a key pair and produce a signed payload for use with the context injection feature.
2 min readUpdated
On this page
Overview #
Authentication is based on Ed25519 asymmetric signing. You generate a private/public key pair, sign a JSON payload with your private key, and register your public key in the admin panel. The system verifies incoming payloads against the registered public key.
Step 1: Generate a Key Pair #
Run the following OpenSSL commands to generate your Ed25519 key pair:
# Generate private key openssl genpkey -algorithm Ed25519 -out private_key.pem # Extract public key openssl pkey -in private_key.pem -pubout -out public_key.pem # View public key (paste this into the admin panel) cat public_key.pem
Important: Keep private_key.pem secret. Only the public key is shared.
Step 2: Register Your Public Key #
Paste the contents of public_key.pem into the admin panel and assign it a Key ID — a human-readable identifier for your key (e.g. teddy-key). This Key ID must match the keyId field in your payload.
Step 3: Sign a Payload #
Install the cryptography Python library if you haven't already:
pip install cryptography
Use the following script to produce a signed payload:
import json import time import uuid import base64 from cryptography.hazmat.primitives.serialization import load_pem_private_key from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey with open("private_key.pem", "rb") as f: private_key: Ed25519PrivateKey = load_pem_private_key(f.read(), password=None) payload = { "keyId": "teddy-key", # Must match the Key ID registered in the admin panel "timestamp": int(time.time()), # Unix timestamp (seconds) "nonce": str(uuid.uuid4()), # Unique per request "name": "", # User display name "email": "", # User email address "roles": ["Student"], # User roles "externalData": { "name": "teddy", "programme": "BSc Computer Science", "srn": "123456789", "year_of_study": 2, "groups": ["oc-cosci", "reg-cosci"], }, } # JCS-style canonicalization canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=True) # Sign sig_bytes = private_key.sign(canonical.encode("utf-8")) signature = base64.urlsafe_b64encode(sig_bytes).rstrip(b"=").decode() payload["signature"] = signature print(json.dumps(payload, indent=2))
Payload Structure #
| Field | Type | Description |
|---|---|---|
keyId |
string | Identifies which public key to verify against |
timestamp |
integer | Unix timestamp of when the payload was created |
nonce |
string | UUID, unique per request to prevent replay attacks |
name |
string | User's display name |
email |
string | User's email address |
roles |
array | List of roles assigned to the user (e.g. ["Student"]) |
externalData |
object | Arbitrary additional data about the user |
signature |
string | Base64url-encoded Ed25519 signature (added after signing) |
Example Output
{ "keyId": "teddy-key", "timestamp": 1775829992, "nonce": "140395ba-fd85-4d77-8551-0e70e090019e", "name": "", "email": "", "roles": ["Student"], "externalData": { "name": "teddy", "programme": "BSc Computer Science", "srn": "123456789", "year_of_study": 2, "groups": ["oc-cosci", "reg-cosci"] }, "signature": "SvTN7H2DGRgY0ftf62RTCIj-NAwQAImyFtMVAmgjb6zKdY3uMKnm_RTCgD0b9Vu1v7jb..." }
Notes #
- The payload is canonicalized using sorted keys and compact separators before signing. The
signaturefield must not be present during canonicalization — it is appended after. - The signature is base64url-encoded with padding stripped.
- Timestamps should be recent — stale payloads may be rejected.
- Each request should use a fresh nonce to prevent replay attacks.
Still stuck?
Ask the LearnWise assistant. It answers from these guides.
Related guides
- How do I enable Context Injection in LearnWise?Integrations
- How do I enable SCORM content ingestion in Brightspace?Integrations
- How do I Install Google Analytics 4 Event Tracking?Integrations
- How do I integrate LearnWise with Freshdesk (Native)?Integrations
- How do I integrate LearnWise with Merge ticketing integrations?Integrations