descope/django-descope

Descope plugin for Django framework

app
authentication
descope
django
plugin
python
sdk

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

  2. Get your project id

  3. Create two roles in Descope, that will be mapped to Django permissions
  4. is_staff
  5. 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
Stars
23
100.00% more than last month
Forks
3
Open Issues
3