View Source LightningWeb.Plugs.WebhookAuth (Lightning v2.10.4)
A Plug to authenticate and authorize requests based on paths starting with '/i/'. It verifies the presence of correct API keys or Basic Authentication credentials.
Summary
Functions
Handles the incoming HTTP request and performs authentication and authorization checks
based on paths starting with /i/
.
Initializes the options.
Functions
Handles the incoming HTTP request and performs authentication and authorization checks
based on paths starting with /i/
.
Details
This function is the entry point for the WebhookAuth
plug. It first checks if
the request path starts with /i/
to determine whether the request should be processed
by this plug.
If the path matches, it then extracts the webhook
part from the request path and
runs to fetch the corresponding trigger
using the fetch_trigger
function.
If a valid trigger
is found, the function proceeds to validate the authentication
of the request using the validate_auth
function.
In case the trigger
is not found, or the path does not start with /i/
, the function
returns a 404 Not Found response with a JSON error message indicating that the webhook
is not found.
Parameters
conn
: The connection struct representing the incoming HTTP request._opts
: A set of options, not used in this function but is a mandatory parameter as per Plug specification.
Returns
- A connection struct representing the outgoing response, which can be a successful response, an unauthorized response, or a not found response, based on the evaluation of the above-mentioned conditions.
Examples
Assuming a request with the path /i/some_webhook
:
Webhook Found and Authenticated
iex> LightningWeb.Plugs.WebhookAuth.call(conn, [])
%Plug.Conn{status: 200, ...}
iex> LightningWeb.Plugs.WebhookAuth.call(conn, [])
%Plug.Conn{status: 404, ...}
Initializes the options.