Connecting Ghost and GToolkit

As GToolkit is my integrated development environment, I want to be able to quickly post articles on my Ghost instance. Ghost has a REST API, so that should be straight forward. Let's see how we do.

client := ZnClient new.
client url: 'https://{admin_domain}/ghost/api/admin/{resource}.
client get.
Authorization failed
Accessing the posts, try 1

That means I need to go to settings, advanced, integrations and add a custom integration.

With a custom integration with GToolkit shown
UI of the add custom integration settings

When I add an integration, I get a public and a secret key added together with a colon as admin_api. I need to split them, as Ghost wants the public key added as kid field to the JWT token header.

Split on :
Splitting the admin api key

Getting JWT tokens to work is always annoying, as there are so many tiny things that can go wrong and the error messages are always useless. The public key can be added directly, but the signing needs to happen with the string converted from a hex string. The timestamps for issuing and expiration time need to be in unix time format.

Ghost expects the public key kid field in the header, which was not supported in the JWT implementation but trivial to add.

add a kid dictionary association to properties of JOSEHeader
kid accessor

The authorization is then set as

client request setAuthorization: 'Ghost ',tokenString.
JSON structured data as a result of the request for all posts
The posts can be accessed

And of course, don't forget to regenerate keys after making screenshots showing them