# 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._
2. Install "django-descope" and add to your INSTALLED_APPS setting like this:
```bash
poetry add django-descope
OR
pip install django-descope
```
```
INSTALLED_APPS = [
...
'django_descope',
]
```
3. Add Descope Middleware **after** the AuthenticationMiddleware and SessionMiddleware
```
MIDDLEWARE = [
...
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'django_descope.middleware.DescopeMiddleware',
]
```
4. Include descope URLconf in your project urls.py like this:
```
path('auth/', include('django_descope.urls')),
```
5. In your site templates, insert the `descope_flow` tag where you want to place your flow
```html
{% 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 %}
```
6. Start the development server and visit the newly created view
## Testing
See [test_admin.py](example_app/test_admin.py) for a rudimentary example of
how to utilize [Descope Test Users](https://docs.descope.com/manage/testusers/)
when testing your application with authenticated users.
You can use the helper [`django_descope.authentication.add_tokens_to_request`](django_descope/authentication.py) to add the tokens to the django session
> [!IMPORTANT]
> Remember you must create the relevant roles in [Descope Console](https://app.descope.com)
> 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/descope/django-descope",
"name": "django_descope",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8.1",
"maintainer_email": null,
"keywords": "descope, jwt, authentication, django",
"author": "Descope",
"author_email": "info@descope.com",
"download_url": "https://files.pythonhosted.org/packages/d0/de/56856308614092c87f61d97a01558cd08a6be9a4187b629add0216144416/django_descope-1.4.0.tar.gz",
"platform": null,
"description": "# Descope Django App\n\nDescope is a user management and authentication platform.\nThis plugin integrates Descope with your Django app.\n\n## Quick start\n\n1. Sign up for Descope and set admin roles\n\n- Get your project id\n- Create two roles in Descope, that will be mapped to Django permissions\n - is_staff\n - is_superuser\n\nMap these roles to any user you would like to make a staff or superuser in your Django app.\n_The names of these roles can be customized in the settings below._\n\n2. Install \"django-descope\" and add to your INSTALLED_APPS setting like this:\n\n```bash\npoetry add django-descope\nOR\npip install django-descope\n```\n\n```\n INSTALLED_APPS = [\n ...\n 'django_descope',\n ]\n```\n\n3. Add Descope Middleware **after** the AuthenticationMiddleware and SessionMiddleware\n\n```\n MIDDLEWARE = [\n ...\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n ...\n 'django_descope.middleware.DescopeMiddleware',\n ]\n```\n\n4. Include descope URLconf in your project urls.py like this:\n\n```\n path('auth/', include('django_descope.urls')),\n```\n\n5. In your site templates, insert the `descope_flow` tag where you want to place your flow\n\n```html\n{% load descope %}\n<!-- load the descope registry -->\n\n{% if user.is_authenticated %}\n<h1>Welcome {{ user.email }} you are logged in!</h1>\n<p><a href=\"{% url 'logout' %}\">Log Out</a></p>\n{% else %} {% descope_flow \"sign-up-or-in\" \"/\" %}\n<!-- provide the descope flow id, and where to redirect after a successful login-->\n{% endif %}\n```\n\n6. Start the development server and visit the newly created view\n\n## Testing\n\nSee [test_admin.py](example_app/test_admin.py) for a rudimentary example of\nhow to utilize [Descope Test Users](https://docs.descope.com/manage/testusers/)\nwhen testing your application with authenticated users.\nYou can use the helper [`django_descope.authentication.add_tokens_to_request`](django_descope/authentication.py) to add the tokens to the django session\n\n> [!IMPORTANT]\n> Remember you must create the relevant roles in [Descope Console](https://app.descope.com)\n> so you can utilize them in your testing.\n\n## Settings\n\nThe following settings are available to configure in your project `settings.py`\n\n#### Required\n\n```\nDESCOPE_PROJECT_ID\n```\n\n#### Optional\n\n```\nDESCOPE_MANAGEMENT_KEY\nDESCOPE_IS_STAFF_ROLE\nDESCOPE_IS_SUPERUSER_ROLE\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Descope plugin for Django",
"version": "1.4.0",
"project_urls": {
"Documentation": "https://docs.descope.com",
"Homepage": "https://github.com/descope/django-descope",
"Repository": "https://github.com/descope/django-descope"
},
"split_keywords": [
"descope",
" jwt",
" authentication",
" django"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7e861c0514213edd13d951d26bdd033a5fd6ffee2eca8cd170fed1deebbd1ac4",
"md5": "9c4b3a272da53bb1dcee8b8a4b4a8390",
"sha256": "780f86af628c4d2f43ca2146b382dcd624caadaa74b982a4fde933d04524350b"
},
"downloads": -1,
"filename": "django_descope-1.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9c4b3a272da53bb1dcee8b8a4b4a8390",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 12715,
"upload_time": "2024-08-18T18:58:03",
"upload_time_iso_8601": "2024-08-18T18:58:03.967290Z",
"url": "https://files.pythonhosted.org/packages/7e/86/1c0514213edd13d951d26bdd033a5fd6ffee2eca8cd170fed1deebbd1ac4/django_descope-1.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d0de56856308614092c87f61d97a01558cd08a6be9a4187b629add0216144416",
"md5": "52704cda78586109169a4c6b5732cf67",
"sha256": "69f00daa261e83e3c4141c41e3d6552e46c60450521069a58a0b076d30a55781"
},
"downloads": -1,
"filename": "django_descope-1.4.0.tar.gz",
"has_sig": false,
"md5_digest": "52704cda78586109169a4c6b5732cf67",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 8424,
"upload_time": "2024-08-18T18:58:04",
"upload_time_iso_8601": "2024-08-18T18:58:04.816811Z",
"url": "https://files.pythonhosted.org/packages/d0/de/56856308614092c87f61d97a01558cd08a6be9a4187b629add0216144416/django_descope-1.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-18 18:58:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "descope",
"github_project": "django-descope",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django_descope"
}