Skip to main content

A OIDC EntraID authentication backend for django.

Project description

django-epfl-entra-id

Test Status

Entra ID authentication for Django.

Requirements

  • Python 3.6 or later
  • Django 1.11, 2.2, 3.2 or 4.2

Installation

pip install django-epfl-entra-id

Documentation

Settings

Add 'mozilla_django_oidc' to INSTALLED_APPS:

INSTALLED_APPS = [
  ...
  'django.contrib.auth',
  'mozilla_django_oidc',  # Load after auth
  ...
]

Add django_epfl_entra_id authentication backend:

AUTHENTICATION_BACKENDS = ("django_epfl_entra_id.auth.EPFLOIDCAB",)

Register your application in the App Portal and add the OIDC configuration:

TENANT_ID = os.environ["TENANT_ID"]

OIDC_RP_CLIENT_ID = os.environ["OIDC_RP_CLIENT_ID"]
OIDC_RP_CLIENT_SECRET = os.environ["OIDC_RP_CLIENT_SECRET"]

AUTH_DOMAIN = f"https://login.microsoftonline.com/{TENANT_ID}"
OIDC_OP_AUTHORIZATION_ENDPOINT = f"{AUTH_DOMAIN}/oauth2/v2.0/authorize"
OIDC_OP_TOKEN_ENDPOINT = f"{AUTH_DOMAIN}/oauth2/v2.0/token"
OIDC_OP_JWKS_ENDPOINT = f"{AUTH_DOMAIN}/discovery/v2.0/keys"
OIDC_OP_USER_ENDPOINT = "https://graph.microsoft.com/oidc/userinfo"
OIDC_RP_SIGN_ALGO = "RS256"

LOGIN_URL = '/auth/authenticate'
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

Routing

Edit your urls.py and add the following:

urlpatterns += re_path(r'^auth/', include('mozilla_django_oidc.urls')),

Example template:

{% if user.is_authenticated %}
  <p>Current user: {{ user.username }}</p>
  <form action="{% url 'oidc_logout' %}" method="post">
    {% csrf_token %}
    <input type="submit" value="logout">
  </form>
{% else %}
  <a href="{% url 'oidc_authentication_init' %}?next={{ request.path }}">
    Login
  </a>
{% endif %}

Optional configuration

AUTH_PROFILE_MODULE = "userprofile.UserProfile"

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_epfl_entra_id-0.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_epfl_entra_id-0.0.1-py2.py3-none-any.whl (4.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_epfl_entra_id-0.0.1.tar.gz.

File metadata

  • Download URL: django_epfl_entra_id-0.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.4 CPython/3.13.0 Linux/6.8.0-64-generic

File hashes

Hashes for django_epfl_entra_id-0.0.1.tar.gz
Algorithm Hash digest
SHA256 db616e1efddf41283bb6f44761258e897b512187d7f0f87281fe7a343287a692
MD5 45ab12f09e92b46c124f3dc92211fbbc
BLAKE2b-256 ee772472927dc1be834635d9a9ccf9a0b68cef1112fc40ac930a8647a71f1bfc

See more details on using hashes here.

File details

Details for the file django_epfl_entra_id-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_epfl_entra_id-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb9f8b61aa73e8eb1ca9081d52a9140855112e7340b620cb5091c758db371f88
MD5 1535705e6c0785538b23926b942cd778
BLAKE2b-256 e803806776ef5bd5eb92665efc74c6b83f454b482575b71c3b4e20491b1ca1e3

See more details on using hashes here.

Supported by

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