Guides
Notifications

Verify the signature

Confirm a notification came from the simulated Okto by checking X-Payload-Signature with the sandbox's RSA public key.

Every notification carries the X-Payload-Signature header: a SHA256withRSA signature (RSASSA-PKCS1-v1_5 with SHA-256) of the exact body bytes, base64-encoded. Each Mimicr sandbox has its own 2048-bit RSA key pair; the private key never leaves Mimicr and the public key is yours.

Get the public key

In the console (Okto, operator tab) or in the control API:

bash
curl --url https://api.mimicr.dev/v1/okto \
  --header 'Authorization: Bearer mk_...'

The public_key field holds the PEM key (-----BEGIN PUBLIC KEY-----, SPKI). Store it in your application's configuration. It doesn't change on "Reiniciar dados" (reset).

Rules

  • Verify the raw body, before any parsing. Re-serializing the JSON changes bytes (whitespace, order, accents) and breaks the signature.
  • Base64-decode the header before verifying.
  • Reject (401) when the signature doesn't match. Also compare the Gaming-Operator-Token header with the notificationToken you set.
  • Retries and resends send the same body with the same signature.

Node.js

javascript
import express from "express";
import { createVerify } from "node:crypto";

const OKTO_PUBLIC_KEY = process.env.OKTO_PUBLIC_KEY; // PEM from the public_key field
const NOTIFICATION_TOKEN = process.env.OKTO_NOTIFICATION_TOKEN;

const app = express();

app.post("/webhooks/okto/deposit", express.raw({ type: "application/json" }), (req, res) => {
  const signature = req.get("X-Payload-Signature") ?? "";
  const valid = createVerify("RSA-SHA256").update(req.body).verify(OKTO_PUBLIC_KEY, signature, "base64");
  if (!valid || req.get("Gaming-Operator-Token") !== NOTIFICATION_TOKEN) return res.sendStatus(401);

  const notification = JSON.parse(req.body.toString("utf8"));
  const invoice = notification.Invoice;
  // credit the player when invoice.status === "paid", only once per invoice.id
  res.sendStatus(200);
});

app.listen(3000);

Python

python
import base64
import os

from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
from flask import Flask, abort, request

PUBLIC_KEY = serialization.load_pem_public_key(os.environ["OKTO_PUBLIC_KEY"].encode())
app = Flask(__name__)


@app.post("/webhooks/okto/deposit")
def okto_deposit():
    body = request.get_data()  # raw bytes
    signature = base64.b64decode(request.headers.get("X-Payload-Signature", ""))
    try:
        PUBLIC_KEY.verify(signature, body, padding.PKCS1v15(), hashes.SHA256())
    except InvalidSignature:
        abort(401)
    if request.headers.get("Gaming-Operator-Token") != os.environ["OKTO_NOTIFICATION_TOKEN"]:
        abort(401)
    invoice = request.get_json()["Invoice"]
    return "", 200

In Java, use Signature.getInstance("SHA256withRSA") with the key loaded from an X509EncodedKeySpec.

Test the verification

Request a sample notification and check what your application answered:

bash
npx mimicr action okto notification.test kind=deposit
npx mimicr get '/v1/okto/deliveries?limit=1'

The delivery shows signature, body (the body sent), last_status_code and last_response. If your application answered 401, check that you verify the raw bytes and that the key belongs to the right sandbox. See also Notifications.