Coder Social home page Coder Social logo

django-azure-ad-sso's Introduction

Django Azure AD OAuth2 SSO

Lightweight Non-Invasive Django Oauth2 Library that uses Azure Active Directory to authenticate users with no registration / login pages for a no frills Seamless Single-Sign-On for Django sites.

Uses existing Django Sessions to authenticate users against Azure Active Directory, returning users immediately to your site after authentication

requires Django > 1.11

this module does not support login over HTTP, HTTPS only must be set (see settings below)

add to settings.py

AUTHENTICATION_BACKENDS = (
 'azure_ad_sso.backends.AzureADBackend',
 'django.contrib.auth.backends.ModelBackend',
)

MIDDLEWARE = (
#...
    'django.contrib.sessions.middleware.SessionMiddleware', 
)

#the email is used as the Django Username

AZURE_AD_SSO_TENANT_ID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

AZURE_AD_SSO_CLIENT_ID = 'YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY'

AZURE_AD_SSO_LOGIN_URL = "/login"

LOGIN_REDIRECT_URL = '/aad_authcomplete'

AZURE_AD_SSO_HOST = 'login.microsoftonline.com'

CSRF_TRUSTED_ORIGINS = [AZURE_AD_SSO_HOST]

SECURE_COOKIE_DOMAIN = AZURE_AD_SSO_HOST

###optionally
AZURE_AD_SSO_POST_LOGOUT_URL = '/where_to_go_after_logout'

#optionally add this middleware to requied login for all views
MIDDLEWARE = (
 ...
 "azure_ad_sso.middleware.SSORequireLoginMiddleware",
)

#these below are required to force https
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

#add these for good measure if you haven't already
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 10
SECURE_HSTS_PRELOAD = True

add to urls.py

from django.conf.urls import url
from azure_ad_sso.backends import AzureADBackend

...
urlpatterns = [
    #...
        url(r'^login/$', AzureADBackend.ad_login),
        url(r'^auth_complete/', AzureADBackend.ad_authcomplete),

    #...
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.