Authentication

One partner secret, two uses: signing session tokens and signing API requests.

Credentials

CredentialUsed forWhere
Partner idIdentifies you in tokens and requestspartner_id claim · x-evelyn-partner header
Partner secretHS256 session tokens · HMAC-SHA256 API requestsYour backend only

!Security

Never expose the partner secret in client-side code, version control or logs. To rotate it, contact us: we add the new secret beside the old one so there is no cutover window, then retire the old one.

Session tokens (embed)

A JWT, alg: HS256, signed with your partner secret. The payload is the session configuration (see Embed Configuration). The embed forwards the token on its own API calls via the x-embed-token header, where the signature is verified.

Node.js (jsonwebtoken)
import jwt from 'jsonwebtoken';

const token = jwt.sign(
  {
    partner_id: 'acme',
    student_id: 'stu_abc123',
    subject: 'math',
    level: 'Grade 6',
    teacher: persona,                       // from the persona catalog
    exp: Math.floor(Date.now() / 1000) + 7200,
  },
  process.env.EVELYN_PARTNER_SECRET,
  { algorithm: 'HS256' },
);
PHP (firebase/php-jwt)
use Firebase\JWT\JWT;

$token = JWT::encode([
    'partner_id' => 'acme',
    'student_id' => 'stu_abc123',
    'subject'    => 'math',
    'level'      => 'Grade 6',
    'teacher'    => $persona,
    'exp'        => time() + 7200,
], $_ENV['EVELYN_PARTNER_SECRET'], 'HS256');

Recommended expiry: 2 hours. The engine allows a 4-hour grace after exp so a long session never fails mid-lesson. Mint a fresh token per session; do not reuse tokens across students.

API request signing (server-to-server)

Every request to /api/portal/v1/* carries three headers. The signature binds the method, path, query, timestamp and body, so a captured request cannot be replayed elsewhere.

Headers
x-evelyn-partner:    acme
x-evelyn-timestamp:  1789450837123          # unix epoch MILLISECONDS, as a string
x-evelyn-signature:  <hex HMAC-SHA256>
Canonical string
signing_string = timestamp + "." + METHOD + "." + path_with_query + "." + raw_body
signature      = hex( HMAC_SHA256( partner_secret, signing_string ) )

METHOD          upper-case, e.g. GET / POST
path_with_query everything after the host, e.g. /api/portal/v1/gaps?studentId=stu_abc123
raw_body        the exact JSON string you send; "" for GET
Node.js (no dependencies)
const crypto = require('crypto');
const BASE = 'https://www.evelynlearning.com';

async function portalFetch(method, path, body) {
  const raw = body === undefined ? '' : JSON.stringify(body);
  const timestamp = String(Date.now());
  const signature = crypto.createHmac('sha256', process.env.EVELYN_PARTNER_SECRET)
    .update(`${timestamp}.${method.toUpperCase()}.${path}.${raw}`)
    .digest('hex');
  const res = await fetch(BASE + path, {
    method,
    headers: {
      'content-type': 'application/json',
      'x-evelyn-partner': 'acme',
      'x-evelyn-timestamp': timestamp,
      'x-evelyn-signature': signature,
    },
    body: raw || undefined,
  });
  return res.json();
}

const gaps = await portalFetch('GET', '/api/portal/v1/gaps?studentId=stu_abc123');
Python (standard library + requests)
import hashlib, hmac, json, os, time, requests

BASE = "https://www.evelynlearning.com"

def portal_request(method: str, path: str, body: dict | None = None):
    raw = "" if body is None else json.dumps(body, separators=(",", ":"))
    ts = str(int(time.time() * 1000))
    sig = hmac.new(os.environ["EVELYN_PARTNER_SECRET"].encode(),
                   f"{ts}.{method.upper()}.{path}.{raw}".encode(), hashlib.sha256).hexdigest()
    return requests.request(method, BASE + path, data=raw or None, headers={
        "content-type": "application/json",
        "x-evelyn-partner": "acme",
        "x-evelyn-timestamp": ts,
        "x-evelyn-signature": sig,
    }).json()

iClock skew

The timestamp must be within ±5 minutes of server time (UTC). A stale_timestamp rejection means your server clock drifted.

Error responses

HTTPreasonMeaning
401missing_auth_headers · unknown_partner · bad_signature · stale_timestamp · bad_timestampFix the signing.
403partner_suspended · endpoint_not_allowedContact us.
429rate_limitedDefault 600 requests/min, burst 60. Honour retryAfterSec.
402quota_exceededDaily request quota (not set for sandboxes).
400bad_requestValidation failed; the failing field is in issues.