A django app with authentication related functionality, a custom user model and object level permissions / groups.
Project description
django-identities
Releases
This project follows the semantic versioning specification for its releases.
Development
Requirements
- Python >=3.7
- Django >=3.2
- django-rest-framework >=3.12
Setup
- Create and activate a python3 venv.
- Install the library in the editable mode
pip install -e .[test,stubs]
- Install dev requirements
pip install -r requirements-dev.txt
. - Install git hooks to automatically format code using black with
pre-commit install
Migrations
To create migrations after modifying database models run ./manage.py makemigrations
Installation
From git in requirements.txt
-
To install this package from this git repository, add the
django-identities
package to therequirements.txt
file. -
Add
guardian
andidentities
tosettings.INSTALLED_APPS
:
INSTALLED_APPS = (
#...
'guardian',
'identities',
#...
)
- Add the following to your
settings
, replacing all values withREPLACE
with your configuration:
AUTH_USER_MODEL = "identities.User"
GUARDIAN_MONKEY_PATCH = False
GUARDIAN_GET_INIT_ANONYMOUS_USER = "identities.models.get_anonymous_user_instance"
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
]
AUTHLIB_OAUTH_CLIENTS = {
"identity_provider": {
"client_id": "REPLACE OIDC client_id",
"client_secret": "REPLACE OIDC client_secret",
"server_metadata_url": "REPLACE OIDC config_url",
"client_kwargs": {"scope": "openid email profile"},
}
}
LOGIN_REDIRECT_URL = "REPLACE OIDC login_redirect_url"
LOGOUT_REDIRECT_URL = "REPLACE OIDC logout_redirect_url"
- In
<app>/urls.py
, extendurlpatterns
like this:
urlpatterns = [
#...
re_path(r"^backend/identity/", include("identities.urls")),
re_path(
r"^backend/identity/auth/local/",
include("rest_framework.urls", namespace="rest_framework"),
),
#...
]
- Extend the file
<app>/templates/rest_framework/base.html
with the following:
{% if user.is_authenticated %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
{{ user.email }}
<b class="caret"></b>
</a>
<ul class="dropdown-menu" style="padding: 0;">
<form action="{% url 'identities:oidc-logout' %}" method="post">
{% csrf_token %}
<button name="logout" value="logout" class="btn btn-default btn-block">
Log out
</button>
</form>
</ul>
</li>
{% else %}
<li>
<a href="{% url 'identities:oidc-authenticate' %}">Log in (federation)</a>
</li>
<li>
<a href="{% url 'rest_framework:login' %}">Log in (local)</a>
</li>
{% endif %}
-
Run
./manage.py migrate
-
Restart your application server
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-identities-2.2.0.tar.gz
(16.4 kB
view details)
Built Distribution
File details
Details for the file django-identities-2.2.0.tar.gz
.
File metadata
- Download URL: django-identities-2.2.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 017e8f2201bf838bdd9ea99601558ca48287cc3ecd30b55042fc17729f6b2e74 |
|
MD5 | d2f98562c1ceb50ce12aa1ddc64c100b |
|
BLAKE2b-256 | 2969e22b835a2e362457088b22f9475609684a14c0a043c337031328e5013cf2 |
File details
Details for the file django_identities-2.2.0-py3-none-any.whl
.
File metadata
- Download URL: django_identities-2.2.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61535007c3caa3c58b5b7ce7daf164d535d9425802262cfb6ffcb79e7da9b9b4 |
|
MD5 | 776581700c340078b75294f151cc69e9 |
|
BLAKE2b-256 | 4dfc006642d994c4acf4f640cc23dc308429c8c14922398d7423e44807b0e34b |