Giter VIP home page Giter VIP logo

django-auth-adfs's Introduction

ADFS Authentication for Django

Documentation Status https://travis-ci.org/jobec/django-auth-adfs.svg?branch=master https://codecov.io/github/jobec/django-auth-adfs/coverage.svg?branch=master

A Django authentication backend for Microsoft ADFS

Features

  • Integrates Django with Active Directory through Microsoft ADFS by using OAuth2.
  • Provides seamless single sign on (SSO) for your Django project on intranet environments.
  • Auto creates users and adds them to Django groups based on info in JWT claims received from ADFS.

Installation

Python package:

pip install django-auth-adfs

In your project's settings.py

AUTHENTICATION_BACKENDS = (
    ...
    'django_auth_adfs.backend.AdfsBackend',
    ...
)

INSTALLED_APPS = (
    ...
    # Needed for the ADFS redirect URI to function
    'django_auth_adfs',
    ...

# checkout config.py for more settings
AUTH_ADFS = {
    "SERVER": "adfs.yourcompany.com",
    "CLIENT_ID": "your-configured-client-id",
    "RESOURCE": "your-adfs-RPT-name",
    # Make sure to read the documentation about the AUDIENCE setting
    # when you configured the identifier as a URL!
    "AUDIENCE": "microsoft:identityserver:your-RelyingPartyTrust-identifier",
    "ISSUER": "http://adfs.yourcompany.com/adfs/services/trust",
    "CA_BUNDLE": "/path/to/ca-bundle.pem",
    "CLAIM_MAPPING": {"first_name": "given_name",
                      "last_name": "family_name",
                      "email": "email"},
    "REDIR_URI": "https://www.yourcompany.com/oauth2/login",
}

########################
# OPTIONAL SETTINGS
########################
TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                # Only needed if you want to use the variable ADFS_AUTH_URL in your templates
                'django_auth_adfs.context_processors.adfs_url',
                ...
            ],
        },
    },
]

MIDDLEWARE = (
    ...
    # With this you can force a user to login without using
    # the @login_required decorator for every view function
    #
    # You can specify URLs for which login is not forced by
    # specifying them in LOGIN_EXEMPT_URLS in setting.py.
    # The values in LOGIN_EXEMPT_URLS are interpreted as regular expressions.
    'django_auth_adfs.middleware.LoginRequiredMiddleware',
)

# Or, when using django <1.10
MIDDLEWARE_CLASSES = (
    ...
    'django_auth_adfs.middleware.LoginRequiredMiddleware',
)

In your project's urls.py

urlpatterns = [
    ...
    # Needed for the redirect URL to function
    url(r'^oauth2/', include('django_auth_adfs.urls')),
    # If you're using Django 1.8, this code should be used instead
    url(r'^oauth2/', include('django_auth_adfs.urls', namespace='django_auth_adfs')),
    ...
]

The URL you have to configure as the redirect URL in ADFS depends on the url pattern you configure. In the example above you have to make the redirect url in ADFS point to https://yoursite.com/oauth2/login

Contributing

Contributions to the code are more then welcome. For more details have a look at the CONTRIBUTING.rst file.

django-auth-adfs's People

Contributors

jobec avatar marcosatti avatar mislavcimpersak avatar

Watchers

 avatar

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.