- Compatibility
Python Version > 3.5
Django Version > 2.0
- Install using
pip install slack-request-permission
Every slack app that needs to interact with any server needs to be verified (verify if the sender is actually slack).
This package offers you:
- Out-of-the-box
Django
permission class that can be used to authenticate slack requests - Framework for creating your own permission class for any slack app
- A standalone method to verify slack request
To use out of the box permission class, all you have to do is add the class into permission classes of Django Rest Framework.
class RandomSlackRequestView(APIView):
permission_classes = (IsSlackAppRequest,)
In settings.py
SLACK_APP_VERSION = 'v0'
SLACK_APP_SIGNING_SECRET = {YOUR_SLACK_APP_SIGNING_SECRET}
The view will verify that the incoming request is from slack before running anything.
There might come a use case where you have different slack apps with different signing_secrets
interacting with your
backend. In that case, you can create your own custom permission class
from slack_request_validator.abstract_permission import AbstractIsSlackAppRequest
class MySlackApp1Permission(AbstractIsSlackAppRequest):
SLACK_APP_VERSION = 'v0'
SLACK_APP_SIGNING_SECRET = {MySlackApp1_SIGNING_SECRET}
class MySlackApp2Permission(AbstractIsSlackAppRequest):
SLACK_APP_VERSION = 'v0'
SLACK_APP_SIGNING_SECRET = {MySlackApp2_SIGNING_SECRET}
These permissions can be then used inside any Django Rest Framework's View
class MySlackApp1View(APIView):
permission_classes = (MySlackApp1Permission,)
class MySlackApp2View(APIView):
permission_classes = (MySlackApp2Permission,)
There might be cases when you don't want to use permission classes. You can directly use the method that verifies slack request
This method returns
either True
or False
True # If slack request is correct
False # If slack request is incorrect
from slack_request_validator.utils import verify_slack_request
slack_version = 'v0'
slack_app_signing_secret = {YOUR_SLACK_APP_SIGNING_SECRET}
verify_slack_request(request=request, slack_app_version=slack_version, slack_app_signing_secret=slack_app_signing_secret)