Skip to main content

PressPass backend and pipelines for the popular Python Social Auth libraries

Project description

Social Auth PressPass

Social Auth PressPass provides backend and pipeline implementations for using PressPass with Python Social Auth. It is available on PyPI as social-auth-presspass, and the primary module import is social_auth_presspass.

When a user logs into your application with PressPass, you will receive a list of the organizations that allow the user to access your app on their behalf.

General Installation

Regardless of your web framework (or lack thereof), there are a few key steps you need to take to start using Social Auth PressPass.

Create a PressPass app

Create a PressPass app using the developer dashboard. The name, price, and access controls are all up to you. Then, make sure of the following in the OpenID Connect section:

  • Response types must include Authorization Code Flow (code), as this is how Social Auth PressPass with authenticate with PressPass itself.

  • Client type must be set to Public. (No, this doesn't mean that anyone will be able to log in; it means that client authentication tokens are cryptographically signed by PressPass itself.)

  • Redirect URIs must include both the development URL and production URL of your application login callback. If you installed Social Auth under the auth/ path in Django, this might look like http://localhost:8000/auth/complete/presspass/. You can add additional paths on each line. Wildcards are not supported, so be exact!

Link your application

In your settings (in Django, this is your settings.py file), set SOCIAL_AUTH_PRESSPASS_KEY to your application's client ID from the PressPass developer dashboard.

From here, you're ready to go! Now you can integrate the PressPass backend into your app just as you would any other Python Social Auth backend. That being said, this can sometimes be tricky, so we've included a Django quickstart below.

Django Installation

  1. Install social-auth-presspass and django-social-auth from PyPI, and follow all the instructions above (in General Installation). You should also follow django-social-auth's setup instructions, though you can augment them to fit your use case with the following steps.

  2. Add the PressPass auth backend to your SOCIAL_AUTH_AUTHENTICATION_BACKENDS setting in settings.py. This will probably look like the following:

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
    'social_auth_presspass.backends.PressPassBackend',
)
  1. Add the PressPass backend as a Django Authentication Backend. To do this, change the following setting:
AUTHENTICATION_BACKENDS = (
    'social_auth_presspass.backends.PressPassBackend',
    ...
)

If you still want to allow some users to log in with a username and password (or if you want to use the Admin Panel login system), be sure to keep Django's built-in ModelBackend in AUTHENTICATION_BACKENDS:

AUTHENTICATION_BACKENDS = (
    'social_auth_presspass.backends.PressPassBackend',
    'django.contrib.auth.backends.ModelBackend',
)
  1. If you want information about a user's organizations, add the PressPass pipelines to your social auth pipelines:
SOCIAL_AUTH_PIPELINE = (
    ...
    'social_auth_presspass.pipelines.extract_organizations',
    'social_auth_presspass.pipelines.link_organizations_to_session',
    ...
)

Note that you should probably put these pipelines after the social_details, social_uid, and auth_allowed built-in pipelines. Note also that you don't need to include link_organizations_to_session unless you would like to access a user's PressPass organizations from inside their session without using their user_information (that is, if you're even keeping track of users).

Backends

This package provides only one backend, social_auth_presspass.backends.PressPassBackend. It inherits from the Python Social Auth OpenID Connect backend, and can be used like any other social auth backend.

User Details

This backend provides the presspass_organizations user detail automatically, which is a list containing information about the organizations that the user is both 1) a member of and 2) has access to the app on behalf of. The key fields in each organization are uuid and name.

Pipelines

This package provides one pipeline, social_auth_presspass.pipelines.link_organizations_to_session, which is intended to help apps leverage the PressPass authentication system in lieu of their own. This pipeline creates two session variables for the PressPass-authenticated visitor:

  • presspass_authenticated: True if the visitor has been authenticated with PressPass (we recommend you use this as session.get('presspass_authenticated', False)), as there is no guarantee that this value is defined and non-null.

  • presspass_organizations: a list of organizations the visitor is authorized to access your app as a member of (each organization is a dict serialized from data returned from PressPass itself). If a visitor hasn't authenticated with PressPass, this value will not be set. All authenticated visitors will be a member of at least one organization (even if that organization is just an auto-generated personal one).

Examples

For an example app that uses this package for authentication (in lieu of its own user-management system), check out OpenAlerts.

License

This package is licensed under the MIT License (see LICENSE).

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

social-auth-presspass-0.2.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

social_auth_presspass-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file social-auth-presspass-0.2.0.tar.gz.

File metadata

  • Download URL: social-auth-presspass-0.2.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for social-auth-presspass-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e1eee318ebd8f062e77bd5e3a62e0b00f38ad124906e6468dec9b2af7140db05
MD5 5ffd588b0f4a0fdf93e1c553358b4912
BLAKE2b-256 d1c392debf916f8df4fac239266b7aaae74d543a100f522d8b0b0103d2e18e77

See more details on using hashes here.

File details

Details for the file social_auth_presspass-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: social_auth_presspass-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for social_auth_presspass-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 128c1c85da9b15ce3b533510e0ef979d9a606d75a43388ded6b1480e5de79b57
MD5 014047b74436970e0b7c74982542f8f2
BLAKE2b-256 4c46edf2379b339ebfb670bb733544c66eb3569b44be8499412502055bf6ac79

See more details on using hashes here.

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