Welcome to Django Rest Framework MSAL + JWT’s documentation!¶
Contents:
Django Rest Framework MSAL + JWT¶
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
Installation¶
At the command line:
$ easy_install drf-msal-jwt
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv drf-msal-jwt
$ pip install drf-msal-jwt
Usage¶
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.
To use Django Rest Framework MSAL + JWT in a project, add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'drf_msal_jwt',
...
)
Before using this package, you’ll need to register your application with the Microsoft Identity Platform
If you already register then config the settings.py in your app accordingly
DEFAULTS = {
'MSAL_CLIENT_ID': "{AZURE_AD_CLIENT_ID}",
'MSAL_CLIENT_SECRET': "{AZURE_AD_CLIENT_SECRET}",
'MSAL_REDIRECT_URL': "{AZURE_AD_REDIRECT_URL}",
'MSAL_AUTHORITY_URL': 'https://login.microsoftonline.com/common/',
'MSAL_SCOPES': ["User.ReadBasic.All"],
'MSAL_USER_HANDLER': 'django.contrib.auth.models.User',
'MSAL_ALLOW_DOMAINS': ['*'],
'MSAL_CHECK_STATE': True
}
MSAL_CLIENT_ID: Your app Client ID
MSAL_CLIENT_SECRET: Your app Client Secret
MSAL_REDIRECT_URL: Redirect URL when the user logged in successfully
MSAL_AUTHORITY_URL (optional): Your app authority URL
MSAL_SCOPES (optional): scope that you request from the user (User.ReadBasic.All) currently required
MSAL_ALLOW_DOMAINS (optional): Limit the domain that the user can use to sign in, * to allows all domains
MSAL_CHECK_STATE (optional): Check state using session
Be sure configured permission in azure portal according to permission request in MSAL_SCOPES variable.
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)),
...
]
Finally, your client can connect to the backend using these url
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/narongdejsrn/drf-msal-jwt/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
Django Rest Framework MSAL + JWT could always use more documentation, whether as part of the official Django Rest Framework MSAL + JWT docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/narongdejsrn/drf-msal-jwt/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up drf-msal-jwt for local development.
Fork the drf-msal-jwt repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/drf-msal-jwt.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv drf-msal-jwt $ cd drf-msal-jwt/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 drf_msal_jwt tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 3+, and for PyPy. Check https://travis-ci.org/narongdejsrn/drf-msal-jwt/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Narongdej Sarnsuwan <narongdej@sarnsuwan.com>
Contributors¶
None yet. Why not be the first?