{"id":20637161,"url":"https://github.com/izdi/django-slack-oauth","last_synced_at":"2025-10-30T16:07:09.538Z","repository":{"id":29225796,"uuid":"32757540","full_name":"izdi/django-slack-oauth","owner":"izdi","description":"Handles OAuth and stores slack token","archived":false,"fork":false,"pushed_at":"2020-07-19T08:18:44.000Z","size":60,"stargazers_count":54,"open_issues_count":3,"forks_count":26,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T09:54:05.684Z","etag":null,"topics":["django","oauth","pipelines","python","registration","slack"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izdi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-23T20:38:59.000Z","updated_at":"2025-01-01T15:23:07.000Z","dependencies_parsed_at":"2022-07-14T23:30:38.259Z","dependency_job_id":null,"html_url":"https://github.com/izdi/django-slack-oauth","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izdi%2Fdjango-slack-oauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izdi%2Fdjango-slack-oauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izdi%2Fdjango-slack-oauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izdi%2Fdjango-slack-oauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izdi","download_url":"https://codeload.github.com/izdi/django-slack-oauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249161104,"owners_count":21222468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","oauth","pipelines","python","registration","slack"],"created_at":"2024-11-16T15:13:15.473Z","updated_at":"2025-10-30T16:07:04.503Z","avatar_url":"https://github.com/izdi.png","language":"Python","funding_links":[],"categories":[":hammer_and_wrench: \u0026nbsp; Libraries and SDKs"],"sub_categories":["Python"],"readme":"\u003cimg src=\"http://i.imgur.com/YF8yAJS.png\" width=\"80\"\u003e\n\n# Django Slack OAuth [![Build Status](https://travis-ci.org/izdi/django-slack-oauth.svg?branch=master)](https://travis-ci.org/izdi/django-slack-oauth)\n\nA lightweight module for integrating your Django application with Slack.\n\n## Requirements\n\n- Django \u003e= 1.8\n\nTo 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](https://api.slack.com/applications).\n\n\n## Instructions\n\n1. Install using pip:\n\n    ```\n    $ pip install django-slack-oauth\n    ```\n\n2. Add `django_slack_oauth` to `INSTALLED_APPS` in `settings.py`:\n\n    ```python\n    INSTALLED_APPS = (\n        ...\n        'django_slack_oauth',\n    )\n    ```\n\n3. Run initial migrations:\n\n    ```\n    $ python manage.py migrate\n    ```\n\n4. Add Slack OAuth base url to your project's `urls.py`:\n\n    ```python\n    urlpatterns = [\n        ...\n        url(r'^slack/', include('django_slack_oauth.urls')),\n        ...\n    ]\n    ```\n\n5. Specify your Slack credentials and OAuth Scope in `settings.py`:\n\n    ```python\n    SLACK_CLIENT_ID = os.environ.get('SLACK_CLIENT_ID')\n    SLACK_CLIENT_SECRET = os.environ.get('SLACK_CLIENT_SECRET')\n    SLACK_SCOPE = 'admin,bot'\n    ```\n    If you aren't sure what your scope should be, read more about [Slack OAuth Scopes](https://api.slack.com/docs/oauth-scopes).\n\n## Example\n\nAdd a link to Slack OAuth in one of your templates:\n\n```\n\u003ca href='{% url 'slack_auth' %}'\u003eGet slacked\u003c/a\u003e\n```\n\nAfter 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`.\n\nYou can then view the successful request and API data in the Admin under Slack OAuth Requests.\n\n\n## Advanced Usage\n\n### Pipelines\n\nPipelines allow you to create actions after a successful OAuth authentication. Some use cases may be:\n\n- Register an account for the user\n- Capture returned API data from Slack after authentication (Default Behaviour)\n- Send Slack messages to the user's Slack team after authentication\n\nThey 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.\n\nPipelines are defined as a list of callables in `settings.py`:\n\n```python\nSLACK_PIPELINES = [\n    'path.to.function1',\n    'path.to.function2',\n    ...\n]\n```\n\n\n- **Example 1:** Show returned data from the OAuth request\n\n    *settings.py*\n\n    ```python\n    ...\n    SLACK_PIPELINES = [\n        'my_app.pipelines.debug_oauth_request',\n    ]\n    ```\n\n    *my_app/pipelines.py*\n\n    ```python\n    def debug_oauth_request(request, api_data):\n        print(api_data)\n        return request, api_data\n    ```\n\n- **Example 2:** Register User and send an email\n\n    *settings.py*\n\n    ```python\n    ...\n    SLACK_PIPELINES = [\n        'my_app.pipelines.register_user',\n        'my_app.pipelines.send_email',\n    ]\n    ```\n\n    *my_app/pipelines.py*\n\n    ```python\n    from django.contrib.auth.models import User\n\n    from django_slack_oauth.models import SlackUser\n\n\n    def register_user(request, api_data):\n        if api_data['ok']:\n            user, created = User.objects.get_or_create(\n                username=api_data['team_id']+':'+api_data['user_id']\n            )\n\n            if user.is_active:\n                slacker, _ = SlackUser.objects.get_or_create(slacker=user)\n                slacker.access_token = api_data.pop('access_token')\n                slacker.extras = api_data\n                slacker.save()\n\n            if created:\n                request.created_user = user\n\n        return request, api_data\n\n\n    def notify(request, api_data):\n        if hasattr(request, 'created_user'):\n            notify_admins(\"New user with id {} has been created.\".format(request.created_user))\n            notify_user(request.created_user)\n\n        return request, api_data\n    ```\n\n_Thanks to_ [Daniel van Flymen](https://github.com/dvf)\n\n### Slack Endpoints\n\nThe following parameters may be overriden, in the (rare) case that Slack changes their endpoints:\n\n```python\nSLACK_AUTHORIZATION_URL = 'https://slack.com/oauth/authorize'\nSLACK_OAUTH_ACCESS_URL = 'https://slack.com/api/oauth.access'\n```\n\n### Forgery Attacks\n\nTo 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](https://docs.djangoproject.com/en/2.1/topics/http/sessions/#enabling-sessions) (on by default).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizdi%2Fdjango-slack-oauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizdi%2Fdjango-slack-oauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizdi%2Fdjango-slack-oauth/lists"}