Created
February 19, 2026 09:04
-
-
Save 7ute/ba3ebd1977366e2678bb0f7ad6b8ee39 to your computer and use it in GitHub Desktop.
PHP Ghost Admin Token Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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