django-epfl-entra-id


Namedjango-epfl-entra-id JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryCustom Microsoft Entra ID Authentication Backend for Django.
upload_time2025-07-30 06:11:11
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
keywords django entraid oidc authentication
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-epfl-entra-id

[![Test Status][github-actions-image]][github-actions-url]

Custom [Microsoft Entra ID][entra-id] Authentication Backend for Django.

## Requirements

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

## Installation

```bash
pip install django-epfl-entra-id
```

## Documentation

### Settings

Add `'mozilla_django_oidc'` to `INSTALLED_APPS`:

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

Add `django_epfl_entra_id` authentication backend:

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

Register your application in the [App Portal][app-portal] and add the OIDC
configuration:

```python
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:

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

Example template:

```htmldjango
{% 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

```python
AUTH_PROFILE_MODULE = "userprofile.UserProfile"
```

[github-actions-image]: https://github.com/epfl-si/django-epfl-entra-id/actions/workflows/test.yml/badge.svg?branch=main
[github-actions-url]: https://github.com/epfl-si/django-epfl-entra-id/actions/workflows/test.yml

[entra-id]: https://inside.epfl.ch/identite-numerique/en/digital-identity-protection/
[app-portal]: https://app-portal.epfl.ch/

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-epfl-entra-id",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django, entraid, oidc, authentication",
    "author": null,
    "author_email": "Lindo Duratti <lindo.duratti@epfl.ch>, William Belle <william.belle@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/9b/a2/163d541b275018674acf918ad51d984baac5337572249750cbf36c911c46/django_epfl_entra_id-0.0.2.tar.gz",
    "platform": null,
    "description": "# django-epfl-entra-id\n\n[![Test Status][github-actions-image]][github-actions-url]\n\nCustom [Microsoft Entra ID][entra-id] Authentication Backend for Django.\n\n## Requirements\n\n- Python 3.6 or later\n- Django 1.11, 2.2, 3.2 or 4.2\n\n## Installation\n\n```bash\npip install django-epfl-entra-id\n```\n\n## Documentation\n\n### Settings\n\nAdd `'mozilla_django_oidc'` to `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n  ...\n  'django.contrib.auth',\n  'mozilla_django_oidc',  # Load after auth\n  ...\n]\n```\n\nAdd `django_epfl_entra_id` authentication backend:\n\n```python\nAUTHENTICATION_BACKENDS = (\"django_epfl_entra_id.auth.EPFLOIDCAB\",)\n```\n\nRegister your application in the [App Portal][app-portal] and add the OIDC\nconfiguration:\n\n```python\nTENANT_ID = os.environ[\"TENANT_ID\"]\n\nOIDC_RP_CLIENT_ID = os.environ[\"OIDC_RP_CLIENT_ID\"]\nOIDC_RP_CLIENT_SECRET = os.environ[\"OIDC_RP_CLIENT_SECRET\"]\n\nAUTH_DOMAIN = f\"https://login.microsoftonline.com/{TENANT_ID}\"\nOIDC_OP_AUTHORIZATION_ENDPOINT = f\"{AUTH_DOMAIN}/oauth2/v2.0/authorize\"\nOIDC_OP_TOKEN_ENDPOINT = f\"{AUTH_DOMAIN}/oauth2/v2.0/token\"\nOIDC_OP_JWKS_ENDPOINT = f\"{AUTH_DOMAIN}/discovery/v2.0/keys\"\nOIDC_OP_USER_ENDPOINT = \"https://graph.microsoft.com/oidc/userinfo\"\nOIDC_RP_SIGN_ALGO = \"RS256\"\n\nLOGIN_URL = '/auth/authenticate'\nLOGIN_REDIRECT_URL = \"/\"\nLOGOUT_REDIRECT_URL = \"/\"\n```\n\n### Routing\n\nEdit your `urls.py` and add the following:\n\n```python\nurlpatterns += re_path(r'^auth/', include('mozilla_django_oidc.urls')),\n```\n\nExample template:\n\n```htmldjango\n{% if user.is_authenticated %}\n  <p>Current user: {{ user.username }}</p>\n  <form action=\"{% url 'oidc_logout' %}\" method=\"post\">\n    {% csrf_token %}\n    <input type=\"submit\" value=\"logout\">\n  </form>\n{% else %}\n  <a href=\"{% url 'oidc_authentication_init' %}?next={{ request.path }}\">\n    Login\n  </a>\n{% endif %}\n```\n\n### Optional configuration\n\n```python\nAUTH_PROFILE_MODULE = \"userprofile.UserProfile\"\n```\n\n[github-actions-image]: https://github.com/epfl-si/django-epfl-entra-id/actions/workflows/test.yml/badge.svg?branch=main\n[github-actions-url]: https://github.com/epfl-si/django-epfl-entra-id/actions/workflows/test.yml\n\n[entra-id]: https://inside.epfl.ch/identite-numerique/en/digital-identity-protection/\n[app-portal]: https://app-portal.epfl.ch/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Custom Microsoft Entra ID Authentication Backend for Django.",
    "version": "0.0.2",
    "project_urls": {
        "Changelog": "https://github.com/epfl-si/django-epfl-entra-id/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/epfl-si/django-epfl-entra-id",
        "Source": "https://github.com/epfl-si/django-epfl-entra-id",
        "Tracker": "https://github.com/epfl-si/django-epfl-entra-id/issues"
    },
    "split_keywords": [
        "django",
        " entraid",
        " oidc",
        " authentication"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e74209270bc38c24282af0183efd839301d51e0163a51b73544d96f3bdd75476",
                "md5": "56e9ccb34ac2f524efd86786b2956148",
                "sha256": "218dae32a1678e99cb6ea73f1d541e79f7d41c403758986bf3f7c94c0628cfea"
            },
            "downloads": -1,
            "filename": "django_epfl_entra_id-0.0.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "56e9ccb34ac2f524efd86786b2956148",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4561,
            "upload_time": "2025-07-30T06:11:10",
            "upload_time_iso_8601": "2025-07-30T06:11:10.536490Z",
            "url": "https://files.pythonhosted.org/packages/e7/42/09270bc38c24282af0183efd839301d51e0163a51b73544d96f3bdd75476/django_epfl_entra_id-0.0.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9ba2163d541b275018674acf918ad51d984baac5337572249750cbf36c911c46",
                "md5": "84421066bc14159be9cef05eafc71ed0",
                "sha256": "c207324ad76e9a76f042dc0e7756dc52020f7f246a113a963a2fb78dcb39c603"
            },
            "downloads": -1,
            "filename": "django_epfl_entra_id-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "84421066bc14159be9cef05eafc71ed0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3882,
            "upload_time": "2025-07-30T06:11:11",
            "upload_time_iso_8601": "2025-07-30T06:11:11.868309Z",
            "url": "https://files.pythonhosted.org/packages/9b/a2/163d541b275018674acf918ad51d984baac5337572249750cbf36c911c46/django_epfl_entra_id-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-30 06:11:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "epfl-si",
    "github_project": "django-epfl-entra-id",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-epfl-entra-id"
}
        
Elapsed time: 1.68544s