{ "info": { "author": "POLITICO interactive news", "author_email": "interactives@politico.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Django", "Framework :: Django :: 2.0", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP" ], "description": "![POLITICO](https://politico.com/interactives/cdn/images/badge.svg)\n\n```\n __ _____ _____ __ .__ \n _______/ |______ _/ ____\\/ ____\\ _____ __ ___/ |_| |__ \n / ___/\\ __\\__ \\\\ __\\\\ __\\ \\__ \\ | | \\ __\\ | \\ \n \\___ \\ | | / __ \\| | | | / __ \\| | /| | | Y \\ \n/____ > |__| (____ /__| |__| (____ /____/ |__| |___| / /\\\n \\/ \\/ \\/ \\/ \\/\n```\n\n# POLITICO staff auth\n\nThis app stores a handful of useful utilities we use across our various Django apps at POLITICO to integrate our staff authorization and authentication, which is implemented with Slack via [`Python Social Auth`](https://python-social-auth.readthedocs.io/).\n\n\n## Requirements\n\n- Python 3.6 \u2014 `brew install python`\n\n- Pipenv \u2014 `brew install pipenv`\n\n- Django (tested on versions 2.1.x and 2.2.x)\n\n- A Slack workspace with users\n\n- A Slack app connected to that workspace, with a \"Redirect URL\" entry matching the following pattern:\n\n `http:///social/complete/slack/`\n\n (**Note:** you can have multiple \"Redirect URLs\" for the same app. For local development, you'll be aliasing `localhost` to a subdomain of your choosing, as described in the [\"Domain resolution\"](#domain-resolution) section below.)\n\n- _Optional:_ PostgreSQL \u2014 `brew install postgresql`\n\n\n## What's inside\n\n#### `./staff_auth/`\n\nThe app that handles staff Slack authorization and authentication.\n\n###### `./staff_auth/templates/admin/login.html` and `./staff_auth/static/staff_auth/css/custom-login.css`\n\nCustom HTML and CSS to add a \"Staff login (with Slack)\" button to the standard Django admin login form.\n\n###### `staff_auth.backend.WorkspaceSpecificSlackOAuth2`\n\nA subclass of Python Social Auth's Slack authentication backend. Unlike the original, this variant forces users to log in with credentials from the specified Slack workspace (rather than from any Slack workspace).\n\n###### `staff_auth.middleware.InvalidWorkspaceErrorMiddleware`\n\nA middleware that listens for Python Social Auth's `AuthForbidden` exceptions and maps them to rich output in a [`StaffAuthErrorView`](#staff_authviewsstaffautherrorview) page.\n\n###### `staff_auth.pipeline.promote_staffer_to_staff`\n\nA function that promotes all Slack-authenticated users to \"staff\" status (meaning they can log into the Django admin) when they first sign in with their Slack credentials.\n\n###### `staff_auth.pipeline.promote_manager_to_superuser`\n\nA function that promotes all Slack-authenticated users to \"superuser\" status (meaning they can log into the Django admin) when they first sign in with their Slack credentials \u2014 if the email address on their Slack account matches an email address found in the `settings.MANAGERS` list.\n\n###### `staff_auth.views.StaffAuthErrorView`\n\nAn error page shown to users if they try and log in via a different Slack workspace.\n\n(Note that the HTML and CSS for this view live at `./staff_auth/templates/staff_auth/auth-error.html` and `./staff_auth/static/staff_auth/css/page-styles.css`, respectively.)\n\n#### `./example/`\n\nAn example Django project that shows how we implement staff Slack access.\n\nInside this directory you'll find a standard (if threadbare) Django app, with an example `.env` file, a `Pipfile` and a `manage.py` script at the top level.\n\nInside the `exampleapp` subdirectory is this example app's `settings.py` file (where you can see an example implementation of `politico-staff-auth`'s required configuration variables), along with a `urls.py` file to demonstrate how that piece of wiring should be performed. Standard helper files including `wsgi.py` can also be found in this subdirectory.\n\n\n## Launching the example app\n\n1. Change into the `./example/` directory one level below this README and install dependencies.\n\n ```sh\n cd ./example/\n pipenv install\n ```\n\n2. Create a `.env` file from the `.env.example` template, and insert appropriate values.\n\n ```sh\n cp .env.example .env\n ```\n\n See the [\"Configuration\"](#configuration) section below for more information about what goes in each setting.\n\n3. Create a new blank database, then populate it with the necessary tables.\n\n ```sh\n make database\n pipenv run python manage.py migrate\n ```\n\n4. Start the Django test server.\n\n ```sh\n pipenv run python manage.py runserver\n ```\n\n5. Navigate to [the admin site on your test server](http://local-dev.politicoapps.com:8000/admin/) and click the \"Staff login\" button.\n\n## Installation\n\n1. Install from PyPI:\n\n ```sh\n pipenv install politico-staff-auth\n ```\n\n2. Add `staff_auth` and `social_django` to the list of apps installed into Django.\n\n _In your project's `settings.py`:_\n\n ```python\n INSTALLED_APPS = [\n \"staff_auth\",\n\n # ...\n # Existing installed apps\n # ...\n\n \"social_django\",\n ]\n ```\n\n **NOTE:** The `staff_auth` app must be first in this list (or, at least, must appear before the pre-existing line `django.contrib.admin`). The `social_django` line should appear after all apps that are distributed with Django itself.\n\n3. Add the credentials for your staff's Slack workspace.\n\n _In your project's `settings.py`:_\n\n ```python\n STAFF_AUTH_SLACK_KEY = \"auth-key\"\n\n STAFF_AUTH_SLACK_SECRET = \"secret-key\"\n\n STAFF_AUTH_SLACK_TEAM = \"my-value-here\"\n ```\n\n For more on these values, see the [\"Configuration\"](#configuration) section below.\n\n **NOTE:** We recommend reading these values from environment variables, but there's no accounting for taste.\n\n4. Add the required middleware for rich login error messages.\n\n _In your project's `settings.py`:_\n\n ```python\n MIDDLEWARE = [\n # ...\n # Existing middleware\n # ...\n\n \"staff_auth.middleware.InvalidWorkspaceErrorMiddleware\",\n ]\n ```\n\n **NOTE:** The `staff_auth.middleware.InvalidWorkspaceErrorMiddleware` entry should go at the end of the existing `MIDDLEWARE` list.\n\n5. With the previous steps complete, you can now implement the basic staff auth settings.\n\n _In your project's `settings.py`:_\n\n ```python\n from staff_auth.configured_settings import configure_staff_auth\n\n staff_auth_settings = configure_staff_auth(\n key=STAFF_AUTH_SLACK_KEY,\n secret=STAFF_AUTH_SLACK_SECRET,\n team=STAFF_AUTH_SLACK_TEAM,\n )\n\n for setting_name, setting_value in staff_auth_settings.items():\n globals()[setting_name] = setting_value\n ```\n\n6. Set Django to use the Slack auth backend whenever users are asked to log in.\n\n _In your project's `settings.py`:_\n\n ```python\n LOGIN_URL = \"staff_auth:slack-login\"\n ```\n\n7. Wire up the `staff_auth` and `social_django` URLs.\n\n _In your project's top-level URLconf (`urls.py` file):_\n\n ```python\n urlpatterns = [\n # ...\n # Existing URL patterns\n # ...\n\n path(\"social/\", include(\"social_django.urls\", namespace=\"social\")),\n path(\"staff-auth/\", include(\"staff_auth.urls\")),\n ]\n ```\n\n\n8. _**Optional:**_ Add pipelines.\n\n _In your project's `settings.py`:_\n\n ```python\n SOCIAL_AUTH_PIPELINE = (\n \"social_core.pipeline.social_auth.social_details\",\n \"social_core.pipeline.social_auth.social_uid\",\n \"social_core.pipeline.social_auth.auth_allowed\",\n \"social_core.pipeline.social_auth.social_user\",\n \"social_core.pipeline.user.get_username\",\n \"social_core.pipeline.user.create_user\",\n \"social_core.pipeline.social_auth.associate_user\",\n \"social_core.pipeline.social_auth.load_extra_data\",\n \"staff_auth.pipeline.promote_staffer_to_staff\",\n \"staff_auth.pipeline.promote_manager_to_superuser\",\n \"social_core.pipeline.user.user_details\",\n )\n ```\n\n You can disable either or both of the `staff_auth.pipeline` classes listed above, but please take care to preserve the order seen here \u2014 re-ordering these pipelines could produce unintended and hard-to-debug consequences.\n\n **NOTE:** The behaviors of `staff_auth.pipeline.promote_staffer_to_staff` and `staff_auth.pipeline.promote_manager_to_superuser` are described in the [\"What's inside\"](#whats-inside) section above.\n\n **NOTE 2:** If you're not using either `staff_auth.pipeline` class, skip this step and ensure your project's `settings.py` file has no `SOCIAL_AUTH_PIPELINE` value set.\n\n9. _**Optional:**_ Modify the URLs where users are bounced to when they successfully log in or log out.\n\n These are standard Django settings, and can take either URLs or named URL patterns (as you would pass to the `{% url %}` template tag).\n\n _In your project's `settings.py`:_\n\n ```python\n LOGIN_REDIRECT_URL = \"/my/url/pattern/\"\n\n LOGOUT_REDIRECT_URL = \"/namespace:view-name/\"\n ```\n\n **NOTE:** For more information, see the Django documentation entries [here](https://docs.djangoproject.com/en/2.2/ref/settings/#login-redirect-url) and [here](https://docs.djangoproject.com/en/2.2/ref/settings/#logout-redirect-url).\n\n\n## Configuration\n\n| Setting | What it does |\n|:--|:--|\n| `STAFF_AUTH_SLACK_KEY` | The **'Client ID'** from the Slack \"app\" you've connected to your workspace for authenticating users. Passed to Python Social Auth as `SOCIAL_AUTH_SLACK_KEY`. |\n| `STAFF_AUTH_SLACK_SECRET` | The `Client Secret` from this Slack \"app\". Passed to Python Social Auth as `SOCIAL_AUTH_SLACK_SECRET`. |\n| `STAFF_AUTH_SLACK_TEAM` | The name of the Slack workspace where your users have accounts. (A handy way of remembering this: it's also the subdomain of slack.com where users log in to use Slack itself.) Passed to Python Social Auth as `SOCIAL_AUTH_SLACK_TEAM`. |\n\n\n## Copyright\n\n© 2019–present POLITICO LLC\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/The-Politico/politico-staff-auth/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "politico-staff-auth", "package_url": "https://pypi.org/project/politico-staff-auth/", "platform": "", "project_url": "https://pypi.org/project/politico-staff-auth/", "project_urls": { "Homepage": "https://github.com/The-Politico/politico-staff-auth/" }, "release_url": "https://pypi.org/project/politico-staff-auth/0.0.5/", "requires_dist": [ "social-auth-core", "social-auth-app-django", "ipython ; extra == 'dev'", "pytest ; extra == 'test'" ], "requires_python": "", "summary": "Staff authentication via Slack, the POLITICO way.", "version": "0.0.5", "yanked": false, "yanked_reason": null }, "last_serial": 6007942, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "93e021bffb9ac6eff79cc3030b4b9155", "sha256": "6f0870c1b61b486aa34aa2d8af774aeb25f73e9db582ca790f796fa34743cd2d" }, "downloads": -1, "filename": "politico_staff_auth-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "93e021bffb9ac6eff79cc3030b4b9155", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11815, "upload_time": "2019-09-18T19:02:01", "upload_time_iso_8601": "2019-09-18T19:02:01.220010Z", "url": "https://files.pythonhosted.org/packages/6c/20/990b3a607c018393487b22b92614fd988f799ae3011003223a925232fdae/politico_staff_auth-0.0.1-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "0170c4ebd38c9f9592b92ef544a67bcd", "sha256": "b3e2d6501954b7986604dee3b15b06955dfdbee8284981bda06307618da9881c" }, "downloads": -1, "filename": "politico-staff-auth-0.0.1.tar.gz", "has_sig": false, "md5_digest": "0170c4ebd38c9f9592b92ef544a67bcd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9926, "upload_time": "2019-09-18T19:02:03", "upload_time_iso_8601": "2019-09-18T19:02:03.754322Z", "url": "https://files.pythonhosted.org/packages/fd/5d/682eb2d4a41a9d2e963d8508f01efd33c866d2ab388eb58cdbdc4192a03f/politico-staff-auth-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "c67f639ffcae6d14cfe3e919ddb0e9ba", "sha256": "85569ed53d99d34d6cd8d7c41231acb05859a49053a945395192f5ec3c74b699" }, "downloads": -1, "filename": "politico_staff_auth-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c67f639ffcae6d14cfe3e919ddb0e9ba", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14016, "upload_time": "2019-09-18T19:07:57", "upload_time_iso_8601": "2019-09-18T19:07:57.849713Z", "url": "https://files.pythonhosted.org/packages/2a/cf/58b3574aaaea1ee166dbdd0f42d3d777a6a0203bfe50361cc2f0f4413174/politico_staff_auth-0.0.2-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "80726be2df792952d1410fb571067283", "sha256": "006a7cec8b92881b562625cb89d2b608e8b74104448ece6df58253d648f6f82e" }, "downloads": -1, "filename": "politico-staff-auth-0.0.2.tar.gz", "has_sig": false, "md5_digest": "80726be2df792952d1410fb571067283", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11591, "upload_time": "2019-09-18T19:07:59", "upload_time_iso_8601": "2019-09-18T19:07:59.743934Z", "url": "https://files.pythonhosted.org/packages/e6/e8/e2941f5a5cc5636c222c9feaf779faf8455e047911128dde4a46ff9323d3/politico-staff-auth-0.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "e8e4e42f974bc5a7d3510f829f1fd67c", "sha256": "6ead9c7a85ca125f6661d3f9539f186e537c300a451b854361e7a4b12a019598" }, "downloads": -1, "filename": "politico_staff_auth-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e8e4e42f974bc5a7d3510f829f1fd67c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14110, "upload_time": "2019-09-18T19:19:04", "upload_time_iso_8601": "2019-09-18T19:19:04.029877Z", "url": "https://files.pythonhosted.org/packages/d1/ca/ce494b3fc4c6e1c016b26d1cb23c8e309eecb4b8c50e2ef6b2cc54b6654b/politico_staff_auth-0.0.3-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "301e8696d18513a748b44dcad77ce963", "sha256": "163cf9d935585bed4840e7c7b10cf150727d87320bbce47387d7d3524068a780" }, "downloads": -1, "filename": "politico-staff-auth-0.0.3.tar.gz", "has_sig": false, "md5_digest": "301e8696d18513a748b44dcad77ce963", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11674, "upload_time": "2019-09-18T19:19:05", "upload_time_iso_8601": "2019-09-18T19:19:05.932203Z", "url": "https://files.pythonhosted.org/packages/d9/3b/74b4b7195ba8f709e43877c37e82e03f878766babfaf30aaa4debae20683/politico-staff-auth-0.0.3.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "e481969a2edbb9cd04ed880723cf615c", "sha256": "62fa1ff1d2523568111a072ff7a5a28392bbabea3d58143058ee5c1d783c1ecc" }, "downloads": -1, "filename": "politico_staff_auth-0.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e481969a2edbb9cd04ed880723cf615c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14236, "upload_time": "2019-09-23T19:53:22", "upload_time_iso_8601": "2019-09-23T19:53:22.122878Z", "url": "https://files.pythonhosted.org/packages/38/e3/832cd99a40cb4aee8ac70c03245d836dda2352cb730f1ad274ae7d329eaa/politico_staff_auth-0.0.4-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "bc4891c79b669d77c25753dc00532058", "sha256": "034e40101abf1afa1de7da1b22622efc8f68af94e5c057db5332b6b2ec12d37e" }, "downloads": -1, "filename": "politico-staff-auth-0.0.4.tar.gz", "has_sig": false, "md5_digest": "bc4891c79b669d77c25753dc00532058", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11870, "upload_time": "2019-09-23T19:53:24", "upload_time_iso_8601": "2019-09-23T19:53:24.342777Z", "url": "https://files.pythonhosted.org/packages/b3/a4/65c7b0c68e9c36f7ac126d1dd1d4c2aaf295598916edb8eff00644731854/politico-staff-auth-0.0.4.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "8c673d31e6f08dd3ad635578d5a0dec2", "sha256": "e7a2ad6ec85e6a5cad66bec4d376933096b9579fd1d3e3b81118e81457d0ba6a" }, "downloads": -1, "filename": "politico_staff_auth-0.0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8c673d31e6f08dd3ad635578d5a0dec2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14111, "upload_time": "2019-09-23T20:18:21", "upload_time_iso_8601": "2019-09-23T20:18:21.281395Z", "url": "https://files.pythonhosted.org/packages/81/83/437eed3280041cdac8ae191c02553079d08569dd454b4f54510d9d350090/politico_staff_auth-0.0.5-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "bb4812ba15f3abb53ac3657fabbbe2e2", "sha256": "0f23dfad5e7216c58825966f01815c7511a4599f168501c0ee6f1ec9e60a298a" }, "downloads": -1, "filename": "politico-staff-auth-0.0.5.tar.gz", "has_sig": false, "md5_digest": "bb4812ba15f3abb53ac3657fabbbe2e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11684, "upload_time": "2019-09-23T20:18:24", "upload_time_iso_8601": "2019-09-23T20:18:24.877875Z", "url": "https://files.pythonhosted.org/packages/ba/0d/1cdb10f3b9b19fab3a70593835018486a8b764801a15509c25ed384e9f35/politico-staff-auth-0.0.5.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8c673d31e6f08dd3ad635578d5a0dec2", "sha256": "e7a2ad6ec85e6a5cad66bec4d376933096b9579fd1d3e3b81118e81457d0ba6a" }, "downloads": -1, "filename": "politico_staff_auth-0.0.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8c673d31e6f08dd3ad635578d5a0dec2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14111, "upload_time": "2019-09-23T20:18:21", "upload_time_iso_8601": "2019-09-23T20:18:21.281395Z", "url": "https://files.pythonhosted.org/packages/81/83/437eed3280041cdac8ae191c02553079d08569dd454b4f54510d9d350090/politico_staff_auth-0.0.5-py2.py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "bb4812ba15f3abb53ac3657fabbbe2e2", "sha256": "0f23dfad5e7216c58825966f01815c7511a4599f168501c0ee6f1ec9e60a298a" }, "downloads": -1, "filename": "politico-staff-auth-0.0.5.tar.gz", "has_sig": false, "md5_digest": "bb4812ba15f3abb53ac3657fabbbe2e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11684, "upload_time": "2019-09-23T20:18:24", "upload_time_iso_8601": "2019-09-23T20:18:24.877875Z", "url": "https://files.pythonhosted.org/packages/ba/0d/1cdb10f3b9b19fab3a70593835018486a8b764801a15509c25ed384e9f35/politico-staff-auth-0.0.5.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }