Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active June 23, 2023 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/46c38bee8ace531c164d7e897ba2e9ba to your computer and use it in GitHub Desktop.
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)
# 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