Skip to main content

A django app with authentication related functionality, a custom user model and object level permissions / groups.

Project description

pipeline status coverage report Code style: black

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]
  • Install dev requirements pip install -r requirements-dev.txt.
  • Install git hooks to automatically format code using black with pre-commit install

Installation

From git in requirements.txt

  1. To install this package from this git repository, add the following to the requirements.txt file:
git+ssh://git@git.dcc.sib.swiss/biwg/libweb/django-identities.git@master#egg=django-identities
  1. Add guardian and identities to settings.INSTALLED_APPS:
INSTALLED_APPS = (
    #...
    'guardian',
    'identities',
    #...
)
  1. Add the following to your settings, replacing all values with REPLACE 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"
  1. In <app>/urls.py, extend urlpatterns 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"),
    ),
    #...
]
  1. 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 %}
  1. Run ./manage.py migrate

  2. Restart your application server

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-identities-1.0.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

django_identities-1.0.2-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file django-identities-1.0.2.tar.gz.

File metadata

  • Download URL: django-identities-1.0.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1

File hashes

Hashes for django-identities-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6f5c15f459c479a489dfac974871f6d5126bfb191ad1a1796ec6ac93c2e59d0f
MD5 27140f58253d92251e881f9079898f38
BLAKE2b-256 967b06eaa470002c52808bbec3a52fb8c2006faecf853fbc2ad15a062b6a4d08

See more details on using hashes here.

File details

Details for the file django_identities-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_identities-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1

File hashes

Hashes for django_identities-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8bdf4128c50ea5813a2c7a1631fb1ffcd922dd384b0d95ea4c96170ee1b2231c
MD5 3e16ee4dcc79e341307d891bfb7cf60d
BLAKE2b-256 7323e442413104e51bc72c541647b5b0313491550c52486bae2f9dc56835bb98

See more details on using hashes here.

Supported by

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