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

Syndicate endpoint: Support multiple methods of supplying a token #571

Merged
merged 2 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
--vp-c-indigo-darker: hsl(var(--indigo-h-s) 10%);
--vp-c-indigo-soft: hsl(var(--indigo-h-s) 10% / 0.75);

--vp-c-divider-light-1: hsl(var(--neutral-h-s) 50% / 0.25);
--vp-c-divider-light-2: hsl(var(--neutral-h-s) 50% / 0.125);
--vp-c-divider-light-1: hsl(var(--neutral-h-s) 50% / 0.2);
--vp-c-divider-light-2: hsl(var(--neutral-h-s) 50% / 0.1);
--vp-c-divider-dark-1: hsl(var(--neutral-h-s) 50% / 0.5);
--vp-c-divider-dark-2: hsl(var(--neutral-h-s) 50% / 0.33);

Expand Down
25 changes: 15 additions & 10 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Any application that supports [the Micropub protocol](https://micropub.spec.indi

```sh
POST /micropub HTTP/1.1
Host: indiekit.mywebsite.com
Host: indiekit.website.example
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer XXXXXXX
Authorization: Bearer [ACCESS_TOKEN]

h=entry
&content=Hello+world
Expand Down Expand Up @@ -39,22 +39,27 @@ Note the `mp-syndicate-to` property in the above example. If you’ve configured
You can then send a second `POST` request, this time to `https://indiekit.website.example/syndicate` along with your access token which you can find on your server’s status page:

```sh
POST /syndicate HTTP/1.1
Host: indiekit.mywebsite.com
Content-Type: application/x-www-form-urlencoded

token=XXXXXXX
POST /syndicate?token=[ACCESS_TOKEN] HTTP/1.1
Host: indiekit.website.example
Accept: application/json
```

This will tell Indiekit to syndicate the most recent un-syndicated post to the third-party websites listed in the front matter.
This will tell Indiekit to syndicate the most recent un-syndicated post to the third-party websites listed in a post’s front matter.

::: tip

### Use an outgoing webhook on Netlify

Netlify allows [posting to an outgoing webhook](https://docs.netlify.com/site-deploys/notifications/#outgoing-webhooks) once a deploy has succeeded.
If you are using [Netlify](https://www.netlify.com) to host your website, you can send a notification to the syndication endpoint once a deployment has been completed.

First, create an environment variable for your Indiekit server called `WEBHOOK_SECRET` and give it a secret, hard-to-guess value.

Then on Netlify, in your site’s ‘Build & Deploy’ settings, add an [outgoing webhook](https://docs.netlify.com/site-deploys/notifications/#outgoing-webhooks) with the following values:

* **Event to listen for:** ‘Deploy succeeded’
* **URL to notify:** `[YOUR_INDIEKIT_URL]/syndicate`
* **JWS secret token:** The same value you used for `WEBHOOK_SECRET`

In ‘URL to notify’, enter your server’s syndication endpoint with your access token as the `token` parameter, for example: `https://indiekit.website.example/syndicate?token=XXXXXXX`.
:::

Once this has been completed, Indiekit will update the post, replacing `mp-syndicate-to` with a `syndication` property listing the location of each syndicated copy:
Expand Down
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<form action="{{ application._syndicationEndpointPath }}" method="post">
{{ input({
name: "token",
name: "access_token",
type: "hidden",
value: token
}) | indent(2) }}
Expand Down
46 changes: 44 additions & 2 deletions packages/endpoint-syndicate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,47 @@ Add `@indiekit/endpoint-syndicate` to your list of plug-ins, specifying options

## Supported endpoint queries

- Access token (required): `/syndicate?token=XXXXXXX`
- URL to syndicate: `/syndicate?token=XXXXXXX&source_url=https%3A%2F%2Fwebsite.example%2Fposts%2F1`
- URL to syndicate: `/syndicate?source_url=https%3A%2F%2Fwebsite.example%2Fposts%2F1`

## Authorization

Authorization is needed to update posts with any syndicated URLs. This can be done in a few different ways:

### Query string

Include your server’s access token as the `token` query:

```http
POST /syndicate?token=[ACCESS_TOKEN] HTTP/1.1
Host: indiekit.website.example
Accept: application/json
```

You can find an access token on your server’s status page.

### Form body

Include a value for `access_token` in your form submission:

```http
POST /syndicate HTTP/1.1
Host: indiekit.website.example
Content-type: application/x-www-form-urlencoded
Accept: application/json

access_token=[ACCESS_TOKEN]
```

You can find an access token on your server’s status page.

### Using a webhook secret (Netlify only)

If you are using [Netlify](https://www.netlify.com) to host your website, you can send a notification to the syndication endpoint once a deployment has been completed.

First, create an environment variable for your Indiekit server called `WEBHOOK_SECRET` and give it a secret, hard-to-guess value.

Then on Netlify, in your site’s ‘Build & Deploy’ settings, add an [outgoing webhook](https://docs.netlify.com/site-deploys/notifications/#outgoing-webhooks) with the following values:

- **Event to listen for:** ‘Deploy succeeded’
- **URL to notify:** `[YOUR_INDIEKIT_URL]/syndicate`
- **JWS secret token:** The same value you used for `WEBHOOK_SECRET`
2 changes: 1 addition & 1 deletion packages/endpoint-syndicate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class SyndicateEndpoint {
this.mountPath = this.options.mountPath;
}

get routes() {
get routesPublic() {
router.post("/", syndicateController.post);

return router;
Expand Down
Loading