Skip to main content

A django-allauth dotnetid provider

Project description

django-dotnetid

django-dotnetid is a Django app extending django-allauth. It implements an OpenID connect provider able to map extra_info from the id_token into Django User model. It is also capable of attributing groups automatically.

You need to install django-allauth to be able to use this extension.

A full working example can be found here: https://github.com/sitn/django-dotnetid-example

Quick start

  1. Install requiremed packages in your project:
python -m pip install django-allauth pyjwt cryptography django-dotnetid
  1. Add django_dotnetid to your INSTALLED_APPS setting like this:
    INSTALLED_APPS = [
        ...,
        "django_dotnetid",
        "allauth",
        "allauth.account",
        "allauth.socialaccount",
        "allauth.socialaccount.providers.openid_connect",
    ]
  1. Include the dotnetidprovider URL conf in your project urls.py like this:
from django.urls import include, path
...
    path('accounts/', include('allauth.urls')),
  1. Run python manage.py migrate to create the models.

  2. In your settings.py, you can add the provider like that:

    AUTHENTICATION_BACKENDS = [
        "django.contrib.auth.backends.ModelBackend",
        "allauth.account.auth_backends.AuthenticationBackend",
    ]

    SOCIALACCOUNT_PROVIDERS = {
        "dotnetidprovider": {
            "APP": {
                "provider_id": "dotnetid",
                "name": "Etat de Neuchâtel",
                "client_id": os.environ['DOTNETID_CLIENT_ID'],
                "secret": os.environ['DOTNETID_CLIENT_SECRET'],
                "settings": {
                    "server_url": os.environ['DOTNETID_SERVER_URL'],
                },
            },
            "SCOPE": [
                "profile",
                "openid",
                "glados",
            ],
            "EXTRA_ATTRIBUTES_PREFIX": "djangoopenid",
            "EXTRA_ATTRIBUTES_NAMES": [
                "groups",
                "admin",
            ],
            "OAUTH_PKCE_ENABLED": True,
            "ID_TOKEN_ISSUER": os.environ['DOTNETID_SERVER_URL'],
        }
    }
    SOCIALACCOUNT_EMAIL_VERIFICATION = None
    SOCIALACCOUNT_ADAPTER  = 'django_dotnetid.adapter.DotnetIdAccountAdapter'
    LOGIN_REDIRECT_URL = 'index'
    ACCOUNT_LOGOUT_REDIRECT = 'index'
    SITE_ID = 1

Add allauth.account.middleware.AccountMiddleware at the end of your middlewares:

MIDDLEWARE = [
...
    "allauth.account.middleware.AccountMiddleware",
]
  1. Start the development server.

  2. Visit the /.

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_dotnetid-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

django_dotnetid-1.0.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file django_dotnetid-1.0.0.tar.gz.

File metadata

  • Download URL: django_dotnetid-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_dotnetid-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f11d91a6a306e0a697cc7aa9c55e406281df7abed85d0e9fb48bc8a8930daf7d
MD5 b5c30202a7dc133c09d908817cc05905
BLAKE2b-256 e2c86a284704e57ad39972501864c30505737b77ee439c48deece7a1b09e943e

See more details on using hashes here.

File details

Details for the file django_dotnetid-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dotnetid-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 089175e86fed62fa168db0ca6cbe92f9a37adcfaec30a4fdb97d8a0423800b65
MD5 48d87c9d2e5527529af6237bf7817e44
BLAKE2b-256 5df4cc023ede74a09a61d8cda8eb7c02980e85455f7841486760a6754d87cade

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