<?php

require_once __DIR__ . '/hmac.php';

function og_base64url_encode($data) {
    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}

function og_issue_ticket($secret, $payload) {
    $json = json_encode($payload, JSON_UNESCAPED_UNICODE);
    $payloadB64 = og_base64url_encode($json);
    $sig = og_hmac_sha256_hex($secret, $payloadB64);
    return $payloadB64 . '.' . $sig;
}
