Skip to main content

django-auth-providers is a django app that lets you authenticate to external authentication providers

Project description

django-ext-auth

Django Ext Auth is a package that lets you integrate external authentication providers into your django project.


Overview

If you want to enable authentication against against Azure AD, Google and more, fully compatible with the django authentication backend and session system, this is the package for you.

Supported providers

  • Azure AD (single tenant)
  • Azure AD (multi tenant)
  • Google
  • Facebook
  • Vipps
  • BankID

Requirements

Python 3.12, 3.11, 3.10, 3.9 Django 5.1 <= 4.0

I have not tested lower versions of django and python, so it might be compatible with more versions.

Installation

This is not yet available in pip, so you need to manually clone the repo/download this package.

Place the package in your django project, side by side with your other django apps.

Installed Apps

Add ´ext_auth´ to your INSTALLED_APPS in your settings.py:

INSTALLED_APPS = [
    ...
    'ext_auth',
    ...
]

Middleware

It is also important to add the ´graph_token_middleware´, somewhere after the Session and Authentication middleware:

MIDDLEWARE = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'ext_auth.middleware.tokens.graph_token_middleware',
]

AzureADBackend

Now add the AzureADBackend to your AUTHENTICATION_BACKENDS:

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'ext_auth.backends.AzureADBackend'
]

Urls

ext_auth comes with a sign_in view. For it to work you need to include the urls and set LOGIN_URL. setting the urls:

urlpatterns = [
    ...
    path('admin', admin_site.urls),
    path('auth/', include('ext_auth.urls')),
    ...
]

set the LOGIN_URL in settings.py:

LOGIN_URL = '/auth/signin'

Secrets

Finally we need to set some values in the django settings to be able to contact your provider and complete authentications:

Azure AD

EXT_AUTH_AAD_CLIENT_ID = 'XXXXX-XXXXX-XXXXX-XXXXXX' # The ´Client ID´ for your Azure AD App Registration
EXT_AUTH_AAD_TENANT_ID = 'XXXXX-XXXXX-XXXXX-XXXXXX' # Your Azure AD ´Tenant ID´
EXT_AUTH_AAD_AUTH_AUTHORITY = f"https://login.microsoftonline.com/{EXT_AUTH_AAD_TENANT_ID}" # For single tenant 
EXT_AUTH_AAD_REDIRECT_URI = '/auth/callback' # Should be the path to you callback view
EXT_AUTH_AAD_CLIENT_SECRET = XXXXXXXXXXXXXXXXXXXXX # The client secret from your Azure App Registration
EXT_AUTH_POST_LOGIN_REDIRECT_URI = '/home' # The url that the user will be sent back to after auth is finished
EXT_AUTH_AAD_SCOPES = ["user.read"] # The scoped permissions you want your user to have. user.read is needed to get user data.

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_auth_providers-1.0.8.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

django_auth_providers-1.0.8-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file django_auth_providers-1.0.8.tar.gz.

File metadata

  • Download URL: django_auth_providers-1.0.8.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for django_auth_providers-1.0.8.tar.gz
Algorithm Hash digest
SHA256 3a7b0d03564ad991262e4986c76de74476170247003d6f5d26cd04c8ebebbd01
MD5 9f83bd46278479b5254382dfc0fa30df
BLAKE2b-256 e943a9d4a3765202922f860e59355cf2cf859b01372a340bdf5fe06f04a666c8

See more details on using hashes here.

File details

Details for the file django_auth_providers-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auth_providers-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9d91d7d4b1c3c3ee6adf8a3ca8b87da04d118909e8c4aa43e3a7ffea2afe06d2
MD5 abd94c7a2d7c09fd0e97097b2279bf45
BLAKE2b-256 48800d1b7e7287cc35c5cdbc2149cf080220c56118b31487d9d33c3882ddf914

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