How do I enable Context Injection in LearnWise?
This page is a user-facing guide for enabling and configuring Context Injection in LearnWise.
4 min readUpdated
On this page
1) Add a signing key (Admin Portal → Authentication → Assistant)
#
Context injection requests can be authenticated using Ed25519/HMAC-SHA256/ES256 signatures.
- In the Admin Portal, go to your Assistant.
- Find the Authentication section.
- Add a new Key
Key ID requirements
- This is a human-readable identifier for the key.
- It must match the
keyIdfield used in signed payloads (see Step 5).

2) Enable Context Injection #
- In the Authentication settings, locate Context injection.
- Turn on the Context injection slider.
3) Choose overwrite fields (what this means) #
When context injection runs, LearnWise can either:
- Preserve existing values already known for the user/session, this information is usually delivered if launching from inside an LMS or you have another Authentication method enabled
- Overwrite those values with what your system sends.
Use Overwrite fields to control which fields your injected context is allowed to replace.
Typical guidance:
- Fields sent via context injection are more secure because they are verifiable, if possible, always use the override for all three fields
4) Configure the External Data Source (schema + mapping) #
The External Data Source defines:
- The shape (schema) of allowed incoming
customerParameters - Which fields LearnWise will read and use
If your customerParameters contains keys that don’t match the configured schema, they may be rejected.
4a) Provide a sample JSON schema #
Example shape (illustrative):
{ "name": "string", "programme": "string", "srn": "string", "year_of_study": "number", "groups": "string[]" }

4b) Select fields to use #
In the External Data Source setup UI, select the fields you want LearnWise to ingest (for example: srn, programme, groups, etc.).

4c) Create the Source #
Finalize the setup by creating/saving the source. This source will then be available for context injection to reference.

5) Implement signing in your application #
This section explains how to generate a key pair and produce a signed payload for use with context injection.
Overview #
Authentication is based on Ed25519 asymmetric signing:
- You generate a private/public key pair
- You sign a JSON payload with your private key
- You register your public key in the admin panel
- LearnWise verifies incoming payloads using the registered public key for the provided
keyId
Step 1: Generate a key pair (OpenSSL) #
# 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: Sign a payload (Python example) #
Install the dependency:
pip install cryptography
Use this 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) customerParameters = { "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"] } } # Canonicalize (sorted keys + compact separators) canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False) # 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))
CustomerParameters structure #
| Field | Type | Description |
|---|---|---|
keyId |
string | Identifies which public key to verify against |
timestamp |
integer | Unix timestamp (seconds) for when the payload was created |
nonce |
string | Unique per request to prevent replay attacks |
name |
string | User display name |
email |
string | User email address |
roles |
array | Roles assigned to the user (e.g. ["Student"]) |
externalData |
object | Additional data about the user (must align to your External Data Source schema) |
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_RTCgD0b9Vu1v7jbJD3PLkvur-b_mb-KBw" }
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 signing. - 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.
6) Update your injector to send signed custom parameters #
Once signing is implemented, update your injector/service so that the request includes the signed payload in customerParameters (or the appropriate context injection input expected by your integration).
Key checks:
keyIdmatches the configured public key in the Admin Portal- The payload fields align with your External Data Source schema
- The
signatureis computed over the canonicalized payload (without the signature field) - The payload is attached to window.learnWiseSetup under “customerParameters”
window.learnWiseSetup = { host: '<https://aiden.learnwise.ai>', chatSrc: '<https://chat.learnwise.ai>', assistantId: 'xEKm0xSmLbJM', region: 'uk', customerParameters: { "timestamp": "<UTC epoch seconds>", "nonce": "<UUIDv4>", "keyId": "<your-key-id>", "signature": "<base64url for Ed25519/P-256, or standard Base64 for HMAC-SHA256>", "name": "<user name>", "roles": [ "<role1>", "<role2>" ], "externalData": { "programme": "<programme>", "srn": "<srn>", "enrolled": "<enrolled>", "languages": "<languages>" } } }; var script = document.createElement('script'); script.src = window.learnWiseSetup.host + '/chat_launcher.js'; document.head.appendChild(script);
Still stuck?
Ask the LearnWise assistant. It answers from these guides.
Related guides
- Developer Guide: Signed Context InjectionIntegrations
- 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