Last active
June 23, 2023 08:52
-
-
Save piranha/46c38bee8ace531c164d7e897ba2e9ba to your computer and use it in GitHub Desktop.
Making requests to Ghost from restclient.el (or generating JWT in elisp, whatever)
This file contains 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
# use with https://github.com/pashky/restclient.el | |
:admin := << | |
(let* ((key "649484dc581803f494a07f40:dbee81202550e7afe5a022405d8b5b10da9f24d18883c92d5331bace31f6796d") | |
(bits (split-string key ":")) | |
(jwt-header (base64url-encode-string | |
(json-serialize (list :alg "HS256" | |
:typ "JWT" | |
:kid (car bits))))) | |
(payload (base64url-encode-string | |
(json-serialize (list :aud "/admin/" | |
:iat (time-convert (current-time) 'integer) | |
:exp (+ 60 (time-convert (current-time) 'integer)))))) | |
(hexsecret (cadr bits)) | |
(hmac-cmd (string-join '("echo -n '%s.%s'" | |
"openssl dgst -sha256 -mac HMAC -macopt hexkey:%s -binary" | |
"base64" | |
"tr '+/' '-_'" | |
"tr -d '=\n'") | |
" | ")) | |
(hmac (shell-command-to-string | |
(format hmac-cmd jwt-header payload hexsecret)))) | |
(concat jwt-header "." payload "." hmac)) | |
# | |
:auth = Authorization: Ghost :admin | |
# | |
GET http://localhost:2368/ghost/api/admin/tiers/ | |
:auth | |
# | |
GET http://localhost:2368/ghost/api/admin/members/ | |
:auth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment