Skip to content

Instantly share code, notes, and snippets.

@7ute
Created February 19, 2026 09:04
Show Gist options
  • Select an option

  • Save 7ute/ba3ebd1977366e2678bb0f7ad6b8ee39 to your computer and use it in GitHub Desktop.

Select an option

Save 7ute/ba3ebd1977366e2678bb0f7ad6b8ee39 to your computer and use it in GitHub Desktop.
PHP Ghost Admin Token Generator
<?php
use Firebase\JWT\JWT;
class Ghost
{
/**
* @param string $admin_api_key The Ghost Admin API Key
* @param int $ttl Token validity in minutes
*/
public static function adminToken($admin_api_key, $ttl = 5)
{
[$id, $secret] = explode(':', $admin_api_key);
$secretBinary = hex2bin($secret);
$payload = [
'aud' => '/admin/',
'iat' => time(),
'exp' => time() + ($ttl * 60),
];
$headers = [
'kid' => $id,
];
return JWT::encode($payload, $secretBinary, 'HS256', null, $headers);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment