Skip to main content

Descope plugin for Django

Project description

Descope Django App

Descope is a user management and authentication platform. This plugin integrates Descope with your Django app.

Quick start

  1. Sign up for Descope and set admin roles
  • Get your project id
  • Create two roles in Descope, that will be mapped to Django permissions
    • is_staff
    • is_superuser

Map these roles to any user you would like to make a staff or superuser in your Django app. The names of these roles can be customized in the settings below.

  1. Install "django-descope" and add to your INSTALLED_APPS setting like this:
poetry add django-descope
OR
pip install django-descope
   INSTALLED_APPS = [
   ...
   'django_descope',
   ]
  1. Add Descope Middleware after the AuthenticationMiddleware and SessionMiddleware
   MIDDLEWARE = [
   ...
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   ...
   'django_descope.middleware.DescopeMiddleware',
   ]
  1. Include descope URLconf in your project urls.py like this:
   path('auth/', include('django_descope.urls')),
  1. In your site templates, insert the descope_flow tag where you want to place your flow
{% load descope %}
<!-- load the descope registry -->

{% if user.is_authenticated %}
<h1>Welcome {{ user.email }} you are logged in!</h1>
<p><a href="{% url 'logout' %}">Log Out</a></p>
{% else %} {% descope_flow "sign-up-or-in" "/" %}
<!-- provide the descope flow id, and where to redirect after a successful login-->
{% endif %}
  1. Start the development server and visit the newly created view

Testing

See test_admin.py for a rudimentary example of how to utilize Descope Test Users when testing your application with authenticated users. You can use the helper django_descope.authentication.add_tokens_to_request to add the tokens to the django session

[!IMPORTANT] Remember you must create the relevant roles in Descope Console so you can utilize them in your testing.

Settings

The following settings are available to configure in your project settings.py

Required

DESCOPE_PROJECT_ID

Optional

DESCOPE_MANAGEMENT_KEY
DESCOPE_IS_STAFF_ROLE
DESCOPE_IS_SUPERUSER_ROLE

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_descope-2.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_descope-2.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file django_descope-2.1.0.tar.gz.

File metadata

  • Download URL: django_descope-2.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.9.23 Linux/6.11.0-1018-azure

File hashes

Hashes for django_descope-2.1.0.tar.gz
Algorithm Hash digest
SHA256 b8b45a2185f755a40493b3a668dd62c9f9803944afe1035249e7dda32576e1fd
MD5 dd4cb5ac9d5b6cad9d82ad9bc9750640
BLAKE2b-256 7ef02e38fa905371f1a73c8024f12fd9358efcf4f661fa377d6a3d57f7f550fe

See more details on using hashes here.

File details

Details for the file django_descope-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_descope-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.9.23 Linux/6.11.0-1018-azure

File hashes

Hashes for django_descope-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e37f4b8b5c2459d06afdb2a27bdb82ba7c15654e0377894be313aa4a2b0cd25
MD5 496965a61974774d0d7e6b9ca8849538
BLAKE2b-256 1838bec097945d2e2194e34828191f9e6b2624783ab01b37e3df0d5fd6b3ba33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page