Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syndication endpoint not working #567

Closed
sentience opened this issue Dec 29, 2022 · 14 comments
Closed

Syndication endpoint not working #567

sentience opened this issue Dec 29, 2022 · 14 comments
Assignees
Labels
bug Something isn't working sponsor priority Issue opened by a Patron or Benefactor sponsor
Milestone

Comments

@sentience
Copy link
Contributor

Describe the bug

The default syndication endpoint does not appear to be working.

To reproduce

Steps to reproduce the behaviour:

  1. Set up Indiekit with this configuration.
  2. Log into the web admin.
  3. Visit https://indiekit.kevinyank.com/syndicate (Alternatively, visit /syndicate?token=XXXX with a valid token.)
  4. Get a 404 error.

Expected behaviour

Indiekit should respond by syndicating outstanding posts.

Environment

@sentience sentience added the bug Something isn't working label Dec 29, 2022
@sentience
Copy link
Contributor Author

Figured it out from the source code: the endpoint only supports POST.

Not sure why my Netlify web hook didn't work initially, but when I replaced the token with a new one that I verified manually, it all seems to be working now!

@paulrobertlloyd
Copy link
Collaborator

Glad you got it working. Netlify’s webhook has stopped working for me recently, even after updating the token. As far as I can tell it’s a Netlify thing as making a POST request from another app works as expected (as do the syndication buttons in the UI). Do let me know if you come up against the same issue, as it has me mystified!

@sentience
Copy link
Contributor Author

Actually it's not working for me now either. Netlify's UI is no longer complaining of an erroring deploy hook, but my post didn't get auto-syndicated, so I don't know if Netlify actually hit the endpoint.

@sentience
Copy link
Contributor Author

sentience commented Jan 1, 2023

Some relevant findings on #569 as I seek to understand why requests sent from my RapidAPI desktop app cause syndication to occur, but Netlify-sent requests do not.

@paulrobertlloyd paulrobertlloyd added this to the v1.0 milestone Jan 1, 2023
@paulrobertlloyd paulrobertlloyd added the sponsor priority Issue opened by a Patron or Benefactor sponsor label Jan 3, 2023
@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Jan 3, 2023

I think I’ve worked out why this is not working.

Originally, prior to launching the first beta, the syndication endpoint only accepted url and token values from a provided query string (response.query). When I added support for syndicating via the interface, I allowed url and token properties to be provided in a form body (response.body).

However, the ping from Netlify includes a body, and one of its values is url. This is the URL of the site on Netlify (e.g. http://indiekit-sandbox.netlify.app), not the URL to be syndicated. As you can either syndicate the last most recently un-syndicated post, OR syndicate a particular URL, this url value takes precedence.

Two options for resolving:

  1. Have the endpoint only accept parameters via a query string
  2. Rename the url property (and possibly the token property) to something more unique.

(There’s also a third option, workout how to can create a JWS secret token to be sent with the request, which Netlify webhooks can provide. This way the properties would be encoded within a secret token, not query or body parameters. This may be a bit too Netlify-specific however, reducing the usefulness of this endpoint.)

Think I’m tempted to go for option 1, especially as this is the method that worked for a good many months previous.

@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Jan 3, 2023

Actually…

Option 2. Being able to submit via form is a useful feature, and using query strings either requires more workarounds than ideal, or is just plain icky. Instead, look either for request.query.url or request.body.syndication.url.

Also… I think it might be a case of just adding the X-Webhook-Signature header to the list of places we look for an access token. That would mean for that a Netlify webhook, you would add the syndication endpoint URL for ‘URL to notify’, and your server’s access token for ‘JWS secret token (optional)’, which makes much more sense.

@sentience
Copy link
Contributor Author

sentience commented Jan 3, 2023 via email

@sentience
Copy link
Contributor Author

I like the idea of putting the auth token in a header instead (so it doesn't end up in as many logs), but maybe you should continue to support both for people who may need to integrate with a service that doesn't support setting request headers?

@paulrobertlloyd
Copy link
Collaborator

I like the idea of putting the auth token in a header instead (so it doesn't end up in as many logs), but maybe you should continue to support both for people who may need to integrate with a service that doesn't support setting request headers?

Take a look at a61ae7f; I’ve added X-Webhook-Signature to the list of places we look for an access token. Just going to test this now to see if this works as intended.

@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Jan 3, 2023

Could it be possible to move the endpoint for the form submission to a different path, and have the documented /syndicate endpoint for the “deploy hook” functionality remain “dumb”, only taking an auth token?

I think its fine for this endpoint to accept values via query string or form body (after all, this is how the specified Micropub endpoint works, so in that sense its consistent).

Given the syndication endpoint requires authorisation before it can be accessed, and authorised requests are interrogated for an access token in (now) 5 different locations, the documentation for this endpoint should list the places a token can be provided, rather than only mention the query string option. UPDATE: turns out the access token discovered during the authorisation flow isn’t used to authorise the subsequent Micropub request, which is silly.

@paulrobertlloyd
Copy link
Collaborator

So far, I’ve fixed the following:

  • Updated the syndication endpoint such that form body values don’t collide with values sent in Netlify’s webhook POST request body
  • Updated the authorisation flow to follow the same pattern used elsewhere (that is, given the access token discovered during the authorisation flow is saved to the session, use this stored value in the subsequent Micropub request rather than attempt discovery a second time)
  • Provide additional support for Netlify by updating Indiekit’s token search to check if the X-Webhook-Signature header contains a token

And yet still, the syndication endpoint is failing (not helped by me tweaking too many different variables here). I get a notice that the webhook failed after 6 attempts due to a 400/500 error, so I’m guessing authorisation is still failing somewhere (maybe the session gets reset). I’ll need to log the request chain to see what’s happening - perhaps the server’s access token should be stored in the database, rather than memory.

I’ll return to this again tomorrow. 🤪

@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Jan 5, 2023

(Narrator: X-Webhook-Signature didn’t work like Paul thought it did. See #571)

@paulrobertlloyd
Copy link
Collaborator

Think this should be largely fixed, but with the proviso that #575 could cause potential issues for any existing posts in your database.

Fixing #575 would delay releasing the next beta, so think I’ll release the latest changes in Beta 2, and come back to the issue with data falling out of sync later.

@sentience
Copy link
Contributor Author

sentience commented Jan 11, 2023

Looking forward to giving Beta 2 a spin with these changes! I'll work around #575 for now by fixing the out-of-sync data in MongoDB manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sponsor priority Issue opened by a Patron or Benefactor sponsor
Projects
None yet
Development

No branches or pull requests

2 participants