ghostboard / ghost-purge-images

CLI tool to display & purge the uploaded images, video and audio files that currently are not used in any post, page or meta data
MIT License
90 stars 4 forks source link

Error 403 for Ghost 5 in Docker #39

Open ccomb opened 1 year ago

ccomb commented 1 year ago

Hi, I generate the keys and am running this in the container :

CONTENT_KEY=xxxxxxxxxxxxxxxxx ADMIN_KEY=xxxxxxxxxxxxxxxxxxxx ghost-purge-images display --content-key=$CONTENT_KEY --admin-key=$ADMIN_KEY

output: ❌ Error: AxiosError: Request failed with status code 403

ghost log:

Authorization failed

"Unable to determine the authenticated user or integration. Check that cookies are being passed through if using session authentication."

Error ID: 6384b8e0-0502-11ee-8948-e36133aebc76


NoPermissionError: Authorization failed at authorizeAdminApi (/var/lib/ghost/versions/5.49.3/core/server/services/auth/authorize.js:33:25) at Layer.handle [as handle_request] (/var/lib/ghost/versions/5.49.3/node_modules/express/lib/router/layer.js:95:5) at next (/var/lib/ghost/versions/5.49.3/node_modules/express/lib/router/route.js:144:13) at authenticate (/var/lib/ghost/versions/5.49.3/core/server/services/auth/session/middleware.js:28:13) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5)

[2023-06-07 07:10:31] ERROR "GET /ghost/api/v2/admin/posts/?limit=100&page=1&formats=html%2Cmobiledoc" 403 1ms

ccomb commented 1 year ago

I could make it work by replacing http://localhost:2368 with the real hostname in config.production.json.

derek-adair commented 1 year ago

I could make it work by replacing http://localhost:2368 with the real hostname in config.production.json.

I could be wrong here, but i dont think this is the way. When you restart ghost it will not be running on the correct port unless you change what ports docker is forwarding.

FOR ME... I was able to get this working in a reliable way by passing --url=http://localhost:8080 to my purge command

flogaribal commented 2 weeks ago

Does anyone succeed in running ghost-purge-images command on Ghost v5.87.0 ?

I am using docker to deploy my Ghost blog, I installed the package on the running docker and tried to add the --url=http://localhost:2368 to the command but I keep having the following error ❌ Error: AxiosError: Request failed with status code 403

I checked the Ghost log and they are exactly the same as you @ccomb...

ccomb commented 2 weeks ago

To run the purge I have a small script that temporarily replaces localhost with the real hostname:

# install
docker-compose exec ghost npm install -g ghost-purge-images

# purge
CONTENT_KEY=xxxxxxxx......
ADMIN_KEY=xxxxxxxxxxxxx............
# https://github.com/ghostboard/ghost-purge-images/issues/39
docker-compose exec ghost sed -i 's/http:\/\/localhost:2368/https:\/\/www.gorfou.fr/' config.production.json
docker-compose exec ghost ghost-purge-images purge --content-key=$CONTENT_KEY --admin-key=$ADMIN_KEY
docker-compose exec ghost sed -i 's/https:\/\/www.gorfou.fr/http:\/\/localhost:2368/' config.production.json

I have not tested recently.