Skip to main content

Connect Django Rest Framework with MSAL and JWT

Project description

https://badge.fury.io/py/drf-msal-jwt.svg https://travis-ci.org/narongdejsrn/drf-msal-jwt.svg?branch=master https://codecov.io/gh/narongdejsrn/drf-msal-jwt/branch/master/graph/badge.svg

This package allows user to authenticate using Microsoft Account in Django REST Framework.

This library rely on Django REST Framework and Django Rest Framework JWT to works properly. Please make sure you setup these packages successfully before using this package.

Documentation

The full documentation is at https://drf-msal-jwt.readthedocs.io.

Quickstart

Install Django Rest Framework MSAL + JWT:

pip install drf-msal-jwt

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'drf_msal_jwt',
    ...
)

Add Django Rest Framework MSAL + JWT’s URL patterns:

from drf_msal_jwt import urls as drf_msal_jwt_urls


urlpatterns = [
    ...
    url(r'^', include(drf_msal_jwt_urls)),
    ...
]

Config the settings.py

DEFAULTS = {
    'MSAL_CLIENT_ID': "{AZURE_AD_CLIENT_ID}",
    'MSAL_CLIENT_SECRET': "{AZURE_AD_CLIENT_SECRET}",
    'MSAL_AUTHORITY_URL': 'https://login.microsoftonline.com/common/',
    'MSAL_REDIRECT_URL': "{AZURE_AD_REDIRECT_URL}",
    'MSAL_SCOPES': ["User.ReadBasic.All"],
    'MSAL_USER_HANDLER': 'django.contrib.auth.models.User',
    'MSAL_ALLOW_DOMAINS': ['*'],
    'MSAL_CHECK_STATE': True
}

Features

  • [API] for generating Microsoft Login URL

  • [API] for logging/creating user based on Authorization Code, and generate JWT token

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

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

drf-msal-jwt-0.3.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

drf_msal_jwt-0.3.1-py2.py3-none-any.whl (10.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file drf-msal-jwt-0.3.1.tar.gz.

File metadata

  • Download URL: drf-msal-jwt-0.3.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for drf-msal-jwt-0.3.1.tar.gz
Algorithm Hash digest
SHA256 12c08c4fd6d2d1a950c8d18497637ae2f3b52daa4961524d2e9e3eb850669e71
MD5 cee804fc7bde96028fac97fcd1780dd8
BLAKE2b-256 2a376c66f5cfaa628881a6a699a219189ea7af8125f8c264d4ac916f546437ac

See more details on using hashes here.

File details

Details for the file drf_msal_jwt-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: drf_msal_jwt-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for drf_msal_jwt-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5d19de841c506f8bfa9fe13f8b6c31591699f85e267b86ffe974faa235b56563
MD5 8079e087ba8ccf8ca8e17f14594baedf
BLAKE2b-256 d5d4a164fa4f5f1d6b85212ff935efa3388616f786e9f2f467af367a1c7acbae

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