All Projects → izdi → django-slack-oauth

izdi / django-slack-oauth

Licence: MIT license
Handles OAuth and stores slack token

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to django-slack-oauth

aiohttp-login
Registration and authorization (including social) for aiohttp apps.
Stars: ✭ 53 (+3.92%)
Mutual labels:  oauth, registration
users-service
A small microservice for managing user registrations, password changes and issue access tokens
Stars: ✭ 16 (-68.63%)
Mutual labels:  registration
doorkeeper-openid connect
OpenID Connect extension for Doorkeeper
Stars: ✭ 152 (+198.04%)
Mutual labels:  oauth
casdoor
An Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML and CAS, QQ group: 645200447
Stars: ✭ 4,147 (+8031.37%)
Mutual labels:  oauth
oauth2-wechat
微信登录认证授权 Wechat login authorization. This package provides Wechat OAuth 2.0 support for the PHP League's OAuth 2.0 Client
Stars: ✭ 18 (-64.71%)
Mutual labels:  oauth
okta-jhipster-microservices-oauth-example
A microservices architecture built with JHipster, OAuth 2.0, and Okta
Stars: ✭ 29 (-43.14%)
Mutual labels:  oauth
2019-21
🙋‍♀️ 🙋‍♂️ 바글바글(Vaagle): 실시간 질의응답 및 투표 공유 서비스
Stars: ✭ 38 (-25.49%)
Mutual labels:  oauth
aurelia-open-id-connect
An aurelia adapter for the IdentityModel/oidc-client-js
Stars: ✭ 54 (+5.88%)
Mutual labels:  oauth
jenkins-pipeline-shared-library-template
Project template for developing shared Jenkins pipeline libraries.
Stars: ✭ 46 (-9.8%)
Mutual labels:  pipelines
Weibo
[READ ONLY] Subtree split of the SocialiteProviders/Weibo Provider (see SocialiteProviders/Providers)
Stars: ✭ 37 (-27.45%)
Mutual labels:  oauth
torchx
TorchX is a universal job launcher for PyTorch applications. TorchX is designed to have fast iteration time for training/research and support for E2E production ML pipelines when you're ready.
Stars: ✭ 165 (+223.53%)
Mutual labels:  pipelines
DeepI2P
DeepI2P: Image-to-Point Cloud Registration via Deep Classification. CVPR 2021
Stars: ✭ 130 (+154.9%)
Mutual labels:  registration
sonar-auth-gitlab-plugin
Use GitLab OAuth login in SonarQube login page
Stars: ✭ 97 (+90.2%)
Mutual labels:  oauth
azure-aks-kubernetes-masterclass
Azure AKS Kubernetes Masterclass
Stars: ✭ 319 (+525.49%)
Mutual labels:  pipelines
HipHop 2D3Dregistration
2D/3D registration between CT/MRI or STL models and X-ray images (November 2018)
Stars: ✭ 91 (+78.43%)
Mutual labels:  registration
pyTwitchAPI
A Python 3.7 implementation of the Twitch API, EventSub and PubSub
Stars: ✭ 132 (+158.82%)
Mutual labels:  oauth
dpop
DPoP for Web Platform API JavaScript runtimes
Stars: ✭ 20 (-60.78%)
Mutual labels:  oauth
react-google-oauth2.0
React frontend login with OAuth 2.0 & integrates a Rest API backend.
Stars: ✭ 14 (-72.55%)
Mutual labels:  oauth
laravel-api-guide
Laravel 5 project creation guide for REST APIs (needs an update!!)
Stars: ✭ 18 (-64.71%)
Mutual labels:  oauth
Symfony-4-by-Samples
Symfony 4 by Samples is a personal project in which I will be creating small demos with tutorial in which to learn the symfony framework 4. Each of the samples contains a README.md file that indicates the purpose of the sample plus an step by step guide to reproduce it. Basic topics, login and register form, authentication, webpack encore, sass…
Stars: ✭ 40 (-21.57%)
Mutual labels:  registration

Django Slack OAuth Build Status

A lightweight module for integrating your Django application with Slack.

Requirements

  • Django >= 1.8

To use Slack OAuth in your Django app, you'll need your SLACK_CLIENT_ID and SLACK_CLIENT_SECRET which can be found when you Create a New Slack Application.

Instructions

  1. Install using pip:

    $ pip install django-slack-oauth
    
  2. Add django_slack_oauth to INSTALLED_APPS in settings.py:

    INSTALLED_APPS = (
        ...
        'django_slack_oauth',
    )
  3. Run initial migrations:

    $ python manage.py migrate
    
  4. Add Slack OAuth base url to your project's urls.py:

    urlpatterns = [
        ...
        url(r'^slack/', include('django_slack_oauth.urls')),
        ...
    ]
  5. Specify your Slack credentials and OAuth Scope in settings.py:

    SLACK_CLIENT_ID = os.environ.get('SLACK_CLIENT_ID')
    SLACK_CLIENT_SECRET = os.environ.get('SLACK_CLIENT_SECRET')
    SLACK_SCOPE = 'admin,bot'

    If you aren't sure what your scope should be, read more about Slack OAuth Scopes.

Example

Add a link to Slack OAuth in one of your templates:

<a href='{% url 'slack_auth' %}'>Get slacked</a>

After clicking it, you will be redirected to Slack for the OAuth process. If successful, you will be redirected to a view showing a success message. You can change this view by setting SLACK_SUCCESS_REDIRECT_URL in settings.py.

You can then view the successful request and API data in the Admin under Slack OAuth Requests.

Advanced Usage

Pipelines

Pipelines allow you to create actions after a successful OAuth authentication. Some use cases may be:

  • Register an account for the user
  • Capture returned API data from Slack after authentication (Default Behaviour)
  • Send Slack messages to the user's Slack team after authentication

They are simply a list of functions, which get called in order. They must accept and return two parameters: request and api_data, containing the initial request and returned API data respectively.

Pipelines are defined as a list of callables in settings.py:

SLACK_PIPELINES = [
    'path.to.function1',
    'path.to.function2',
    ...
]
  • Example 1: Show returned data from the OAuth request

    settings.py

    ...
    SLACK_PIPELINES = [
        'my_app.pipelines.debug_oauth_request',
    ]

    my_app/pipelines.py

    def debug_oauth_request(request, api_data):
        print(api_data)
        return request, api_data
  • Example 2: Register User and send an email

    settings.py

    ...
    SLACK_PIPELINES = [
        'my_app.pipelines.register_user',
        'my_app.pipelines.send_email',
    ]

    my_app/pipelines.py

    from django.contrib.auth.models import User
    
    from django_slack_oauth.models import SlackUser
    
    
    def register_user(request, api_data):
        if api_data['ok']:
            user, created = User.objects.get_or_create(
                username=api_data['team_id']+':'+api_data['user_id']
            )
    
            if user.is_active:
                slacker, _ = SlackUser.objects.get_or_create(slacker=user)
                slacker.access_token = api_data.pop('access_token')
                slacker.extras = api_data
                slacker.save()
    
            if created:
                request.created_user = user
    
        return request, api_data
    
    
    def notify(request, api_data):
        if hasattr(request, 'created_user'):
            notify_admins("New user with id {} has been created.".format(request.created_user))
            notify_user(request.created_user)
    
        return request, api_data

Thanks to Daniel van Flymen

Slack Endpoints

The following parameters may be overriden, in the (rare) case that Slack changes their endpoints:

SLACK_AUTHORIZATION_URL = 'https://slack.com/oauth/authorize'
SLACK_OAUTH_ACCESS_URL = 'https://slack.com/api/oauth.access'

Forgery Attacks

To avoid forgery attacks we pass the state parameter in the initial authorization request. This state is stored in the session, which requires the session middleware to be enabled (on by default).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].