Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mimiquate/slack_request
https://github.com/mimiquate/slack_request
signature-verification slack slack-webhook webhook
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mimiquate/slack_request
- Owner: mimiquate
- License: apache-2.0
- Created: 2024-05-16T20:48:16.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-05-20T18:28:06.000Z (6 months ago)
- Last Synced: 2024-05-22T18:34:24.012Z (6 months ago)
- Topics: signature-verification, slack, slack-webhook, webhook
- Language: Elixir
- Homepage: https://hex.pm/packages/slack_request
- Size: 38.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔐 SlackRequest
Utilities for verifing an HTTP request can be authenticated as a request
coming from Slack HQ.https://api.slack.com/authentication/verifying-requests-from-slack
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `slack_request` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:slack_request, "~> 1.0.0"}
]
end
```## Usage
### Plug
Set `body_reader:` in `Plug.Parsers` inside your `Endpoint`.
```elixir
# lib/your_app_web/endpoint.exdefmodule YourAppWeb.Endpoint do
...plug Plug.Parsers,
...
body_reader: {SlackRequest.BodyReader, :read_and_cache_body, []}
end
```Plug the `SlackRequest.Plug` in the pipeline that handles your Slack Requests/Webhooks.
Example:
```elixir
# lib/your_app_web/router.exdefmodule YourAppWeb.Router do
...
pipeline :slack do
plug :accepts, ["json"]
plug SlackRequest.Plug
endscope "/slack", YourAppWeb do
pipe_through :slack...
end
```### Manual
Or if just prefer to use the validation function directly:
```elixir
# Somewhere were you're ready to validate the incoming request connif SlackRequest.valid_request?(conn, secret: signing_secret, body: raw_request_body) do
# all good
else
# handle invalid slack request/webhook
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at .## License
Copyright 2024 Mimiquate
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.