Skip to main content

A django app that replaces the django admin authentication mechanism by deferring to an oauth2 provider

Project description

django-admin-oauth2

A django app that replaces the django admin authentication mechanism by deferring to an oauth2 provider.

Build Status

Support

django-admin-oauth2 should support Python 2.7, pypy, and Django versions 1.6 through 1.10

Installation

Step 1: pip install django-admin-oauth2 and include it in your project's requirements

Step 2: Include the django-admin-oauth2 urlconf in your project's urls.py:

url(r'/admin/oauth/', include('oauthadmin.urls'))

Step 3: Include oauthadmin in your INSTALLED_APPS:

INSTALLED_APPS = (
    'oauthadmin'
)

Step 4: Install the middleware in your project's settings.py:

MIDDLEWARE_CLASSES = (
    'oauthadmin.middleware.OauthAdminSessionMiddleware'
)

make sure that this comes AFTER 'django.contrib.sessions.middleware.SessionMiddleware'

Step 5: If you are on Django 1.5 or above, you'll need to set your session serializer to "django.contrib.sessions.serializers.PickleSerializer" since we are storing the pickled user object in the session.

SESSION_SERIALIZER = "django.contrib.sessions.serializers.PickleSerializer"

Step 6: Set up all the correct options (see below for available options)

Settings

  • OAUTHADMIN_GET_USER: This is function that is given the oauth token and returns a django.auth.models.User model corresponding to the currently logged-in user. You can set permissions on this user object and stuff.
  • OAUTHADMIN_CLIENT_ID: Your oAuth client ID
  • OAUTHADMIN_CLIENT_SECRET: oAuth client secret
  • OAUTHADMIN_BASE_URL: The landing point for all oAuth related queries.
  • OAUTHADMIN_AUTH_URL: oAuth provider URL
  • OAUTHADMIN_TOKEN_URL: oAuth bearer token provider URL
  • OAUTHADMIN_PING_INTERVAL (optional, defaults to 300): Minimum number of seconds between ping requests
  • OAUTHADMIN_PING: (optional, defaults to None) This optional function takes an oauth token and returns True if it's still valid and False if it's no longer valid (if they have logged out of the oauth server)
  • OAUTHADMIN_DEFAULT_NEXT_URL: (optional, defaults to /admin). This optional value is the default page that a successful oauth login process will land you on.
  • OAUTHADMIN_SCOPE: (optional, defaults to ['default']). This is a list of authorization scopes.

Testing

If you want to test this app, install the requirements needed for testing:

pip install -r test-requirements.txt

and then run the tests with the provided script:

./runtests.sh

Notes

When the CSRF validation token doesn't match, django-admin-oauth2 will redirect back to the login url so it can retry the authorization step. Sometimes people will bookmark the oauth server with an out-of-date CSRF state string, this is better than showing them an error page.

Changelog

  • 1.2.0: Allow overriding oauth scope with new parameter, OAUTHADMIN_SCOP
  • 1.1.3: Bugfix in adminsite (tabs vs spaces)
  • 1.1.2: Add support for django 2
  • 1.1.1: Fix a bug where the new setting wasn't getting read
  • 1.1.0: Add new setting: OAUTHADMIN_DEFAULT_NEXT_URL
  • 1.0.2: Support python3
  • 1.0.1: Send redirect URI when exchanging grant code for auth token
  • 1.0.0: Add support for django 1.8, 1.9, and 1.10. Drop support for python 2.6. Add support for python 3.5. Update test suite to run with tox.
  • 0.2.6: Roundtrip original URL accessed through the oauth process so you can go to the URL you requested after the authorization process finishes. Thanks @igorsobreira.
  • 0.2.5: Fix bug where failing ping was not invalidating session immediately, only on the second request.
  • 0.2.4: Redirect to the login if the grant is invalid
  • 0.2.3: Redirect to the login if the state is mismatching
  • 0.2.2: Redirect to the login if the state goes missing (sometimes people bookmark the login url)
  • 0.2.1: Added tests for the ping function and fixed a bug with the session variable name for the ping timestamp.
  • 0.2.0: Added support for pinging the auth server to make sure the token is still valid

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

django-admin-oauth2-1.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

django_admin_oauth2-1.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file django-admin-oauth2-1.2.0.tar.gz.

File metadata

  • Download URL: django-admin-oauth2-1.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for django-admin-oauth2-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f51b2c64e43b756aad087ad56441b3fe1fb40abf6ef306f145c56406bb3cc5b5
MD5 df4d5425d952d41a1bb9f373338f44d9
BLAKE2b-256 4352872d780f4c00d4db70021a5e56bdd01e8f41dd642aa14bfce3405c161955

See more details on using hashes here.

Provenance

File details

Details for the file django_admin_oauth2-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_admin_oauth2-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for django_admin_oauth2-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3282eeb69454299f9f969e780e6172b084de6a4fa59e7120437b26ecde003d95
MD5 f23ef7618c064fc582211678949fc220
BLAKE2b-256 cb7c79c423201f16636964f7d1cc58734f77cea24ac255d1a58b2f658b63cfa0

See more details on using hashes here.

Provenance

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