# 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": "",
"docs_url": null,
"requires_python": ">=3.8.1,<4.0",
"maintainer_email": "",
"keywords": "descope,jwt,authentication,django",
"author": "Descope",
"author_email": "info@descope.com",
"download_url": "https://files.pythonhosted.org/packages/a7/d6/1e3647827ca76acbc425654c7f01bac6f9b7e203225edfa84dc3dd4406d5/django_descope-1.3.2.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.3.2",
"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": "e1b0aed2c6d05927af4815ffcf9e5eb35afbcec44e3536722fca64315c3211b8",
"md5": "0fbf4b331529a69f77ef302c3a290648",
"sha256": "c8ac4a1b9e6d1313c294f10d14639cf35a8cefe70e2536f28280badf6d974f81"
},
"downloads": -1,
"filename": "django_descope-1.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0fbf4b331529a69f77ef302c3a290648",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1,<4.0",
"size": 12626,
"upload_time": "2023-12-18T18:36:10",
"upload_time_iso_8601": "2023-12-18T18:36:10.985081Z",
"url": "https://files.pythonhosted.org/packages/e1/b0/aed2c6d05927af4815ffcf9e5eb35afbcec44e3536722fca64315c3211b8/django_descope-1.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a7d61e3647827ca76acbc425654c7f01bac6f9b7e203225edfa84dc3dd4406d5",
"md5": "d825e207ff1026189fc3b575267f09b0",
"sha256": "df8dcd382fc16b11dab73a2d710e528bcc1f8ef89871fcc30eccd9b0157480dd"
},
"downloads": -1,
"filename": "django_descope-1.3.2.tar.gz",
"has_sig": false,
"md5_digest": "d825e207ff1026189fc3b575267f09b0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1,<4.0",
"size": 8325,
"upload_time": "2023-12-18T18:36:12",
"upload_time_iso_8601": "2023-12-18T18:36:12.561298Z",
"url": "https://files.pythonhosted.org/packages/a7/d6/1e3647827ca76acbc425654c7f01bac6f9b7e203225edfa84dc3dd4406d5/django_descope-1.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-18 18:36:12",
"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"
}