You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -174,8 +179,10 @@ First, create a `hooks.yml` file in the `config` directory. This file will defin
174
179
175
180
```yaml
176
181
# file: config/hooks.yml
177
-
handler_plugin_dir: ./plugins/handlers
178
-
auth_plugin_dir: ./plugins/auth
182
+
handler_plugin_dir: ./plugins/handlers # Directory for handler plugins
183
+
auth_plugin_dir: ./plugins/auth # Directory for authentication plugins (optional)
184
+
lifecycle_plugin_dir: ./plugins/lifecycle # Directory for lifecycle plugins (optional)
185
+
instruments_plugin_dir: ./plugins/instruments # Directory for instrument plugins (optional)
179
186
180
187
# Available endpoints
181
188
# Each endpoint configuration file should be placed in the endpoints directory
@@ -213,6 +220,10 @@ auth:
213
220
type: Goodbye # This is a custom authentication plugin you would define in the plugins/auth
214
221
secret_env_key: GOODBYE_API_KEY # the name of the environment variable containing the secret
215
222
header: Authorization
223
+
224
+
# Optional additional options for the endpoint (can be anything you want)
225
+
opts:
226
+
foo: bar
216
227
```
217
228
218
229
#### 3. Implement your handler plugins
@@ -251,6 +262,8 @@ class GoodbyeHandler < Hooks::Plugins::Handlers::Base
251
262
end
252
263
```
253
264
265
+
See the [Handler Plugins](docs/handler_plugins.md) documentation for more information on how to create your own custom handler plugins and what the values of `payload`, `headers`, and `config` are when the `call` method is invoked.
If you want to secure your webhook endpoints, you can create custom authentication plugins in the `plugins/auth` directory. Here is an example of a simple authentication plugin for the `/goodbye` endpoint:
# check if the Authorization header matches the secret
271
-
auth_header = headers[config[:header]]
284
+
auth_header = headers[config[:auth][:header]]
272
285
return false unless auth_header
273
286
274
287
# compare the Authorization header with the secret
@@ -280,6 +293,8 @@ module Hooks
280
293
end
281
294
```
282
295
296
+
To learn more about how you can create your own custom authentication plugins, see the [Auth Plugins](docs/auth_plugins.md) documentation.
297
+
283
298
#### Summary
284
299
285
300
What these steps have done is set up a Hooks server that listens for incoming webhook requests at `/webhooks/hello` and `/webhooks/goodbye`. The `/hello` endpoint will respond with a success message without any authentication, while the `/goodbye` endpoint will require a valid `Authorization` header that matches the secret defined in the environment variable `GOODBYE_API_KEY`. Before the `/goodbye` endpoint enters the defined handler, it will first check the authentication plugin to ensure the request is valid.
0 commit comments