Skip to main content

A python package that authenticates that the request is coming from slack

Project description

Slack Request Permission

License: MIT Python 3.7 Django

Installation

  • Compatibility
Python Version > 3.5
Django Version > 2.0
  • Install using
pip install slack-request-permission

Introduction

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

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.

Framework

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,)

Standalone-Method

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slack-request-permission-1.0.6.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

slack_request_permission-1.0.6-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page