Skip to main content

Simple app to enable Microsoft Account, Office 365 Enterprise, Azure AD, and Xbox Live authentcation as a Django authentcation backend.

Project description

Django Microsoft Authentication Backend

PyPi Python Versions Travis CI Documentation Updates Coverage Maintainability Test Coverage

Simple app to enable Microsoft Account, Office 365 and Xbox Live authentcation as a Django authentcation backend.

Python/Django support

django_microsoft_auth follows the same support cycle as Django, with one exception: no Python 2 support. If you absoutely need Python 2.7 support, everything should largely already work, but you may need to patch microsoft_auth.admin and/or other files to get it to work.

Supported python versions: 3.4+

Supported Django version: 1.11 LTS, 2.0+

Quickstart

  1. Install Django

  2. Install and configure the Sites framework
    • Make sure you update the domain of SITE_ID, this is important and used later. Easy way is to go /admin/sites/site/1/change/ if you have the admin site enabled.

  3. Create a Microsoft OAuth Application
    • write down your client ID

    • Generate an Application Secret, store this somewhere, you will need it for later

    • Add a Web Platform with Allow Implicit Flow and a valid Redirect URL (this will probably be https://<your-domain>/microsoft/auth-callback/), it must be HTTPS

    • Add User.Read under Delegated Permissions

  4. Install package from PyPi:

    pip install django_microsoft_auth
  5. Add the following to your settings.py:

    INSTALLED_APPS = [
        # other apps...
        'django.contrib.sites',
        'microsoft_auth',
    ]
    
    TEMPLATES = [
        {
            # other template settings...
            'OPTIONS': {
                'context_processors': [
                    # other context_processors...
                    'microsoft_auth.context_processors.microsoft',
                ],
            },
        },
    ]
    
    AUTHENTICATION_BACKENDS = [
        'microsoft_auth.backends.MicrosoftAuthenticationBackend',
        'django.contrib.auth.backends.ModelBackend' # if you also want to use Django's authentication
        # I recommend keeping this with at least one database superuser in case of unable to use others
    ]
    
    # pick one
    
    # Microsoft authentication
    # include Microsoft Accounts, Office 365 Enterpirse and Azure AD accounts
    MICROSOFT_AUTH_LOGIN_TYPE = 'ma'
    
    # Xbox Live authentication
    # MICROSOFT_AUTH_LOGIN_TYPE = 'xbl'  # Xbox Live authentication
    
    MICROSOFT_AUTH_CLIENT_ID = 'your-client-id-from-apps.dev.microsoft.com'
    MICROSOFT_AUTH_CLIENT_SECRET = 'your-client-secret-from-apps.dev.microsoft.com'
  6. Add the following to your urls.py:

    urlpatterns = [
        # other urlpatterns...
        url(r'^microsoft/', include('microsoft_auth.urls', namespace='microsoft')),
    ]
  7. Run migrations:

    python manage.py migrate
  8. Start site and goto /admin to and logout if you are logged in.

  9. Login as Microsoft/Office 365/Xbox Live user. It will fail. This will automatically create your new user.

  10. Login as a Password user with access to change user accounts.

  11. Go to Admin -> Users and edit your Microsoft user to have any permissions you want as you normally.

  12. See microsoft_auth/templates/microsoft/admin_login.html for details examples on making a Login form.

See official docs for more details on setup and configuration.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

1.1.0 (2018-7-3)

  • Removes o365 option. New authorization URL works well enough for both
    • Xbox Live Auth still uses old Microsoft Auth URL

    • ‘o365’ will still work as a MICROSOFT_AUTH_LOGIN_TYPE value, but you should change it to ‘ma’

  • Adds extras:
    • ql: DjangoQL package and support

    • test: test dependencies (same as test_requires packages)

    • dev: ql`+`test and extra dev only dependencies like twine and pip-tools

  • Pip 10 support (thanks Shigumitsu!)

  • Fixes max length of o365 IDs (thanks Shigumitsu!)

1.0.6 (2018-4-8)

  • Added patched username validator to allow spaces for usernames for Xbox Live Gamertags

1.0.5 (2018-4-8)

  • Added missing templates and static files to MANIFEST

1.0.4 (2017-12-2)

  • Updated Django category to include 2.0

1.0.3 (2017-12-2)

  • Updated for Django 2.0

1.0.2 (2017-11-27)

  • Changed Development Status category to Stable

1.0.0 (2017-11-19)

  • First release on PyPI.

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_microsoft_auth-1.1.1.tar.gz (47.7 kB view hashes)

Uploaded Source

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