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
This document provides an example of how to implement a custom authentication plugin for a hypothetical system. The plugin checks for a specific authorization header and validates it against a secret stored in an environment variable.
4
+
5
+
In your global configuration file (e.g. `hooks.yml`) you would likely set `auth_plugin_dir` to something like `./plugins/auth`.
6
+
7
+
Here is an example snippet of how you might configure the global settings in `hooks.yml`:
8
+
9
+
```yaml
10
+
# hooks.yml
11
+
auth_plugin_dir: ./plugins/auth # Directory where custom auth plugins are stored
12
+
```
13
+
14
+
Then place your custom auth plugin in the `./plugins/auth` directory, for example `./plugins/auth/some_cool_auth_plugin.rb`.
15
+
16
+
```ruby
17
+
# frozen_string_literal: true
18
+
# Example custom auth plugin implementation
19
+
module Hooks
20
+
module Plugins
21
+
module Auth
22
+
class SomeCoolAuthPlugin < Base
23
+
def self.valid?(payload:, headers:, config:)
24
+
# Get the secret from environment variable
25
+
secret = fetch_secret(config) # by default, this will fetch the value of the environment variable specified in the config (e.g. SUPER_COOL_SECRET as defined by `secret_env_key`)
0 commit comments