{ "info": { "author": "Mohamed El-Kalioby", "author_email": "mkalioby@mkalioby.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Framework :: Django :: 2.2", "Framework :: Django :: 3.0", "Framework :: Django :: 3.1", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# django-mfa2\nA Django app that handles MFA, it supports TOTP, U2F, FIDO2 U2F (Web Authn), Email Tokens , and Trusted Devices\n\n### Pip Stats\n[](https://badge.fury.io/py/django-mfa2)\n[](https://pepy.tech/project/django-mfa2)\n\n### Conda Stats\n[](https://anaconda.org/conda-forge/django-mfa2) \n[](https://anaconda.org/conda-forge/django-mfa2) \n[](https://anaconda.org/conda-forge/django-mfa2) \n\nWeb Authencation API (WebAuthn) is state-of-the art techology that is expected to replace passwords.\n\n\n\nFor FIDO2, the following are supported\n * **security keys** (Firefox 60+, Chrome 67+, Edge 18+, Safari 13 on Mac OS, Chrome on Andriod, Safari on iOS 13.3+),\n * **Windows Hello** (Firefox 67+, Chrome 72+ , Edge) ,\n * **Apple's Touch ID/Face ID** (Chrome 70+ on Mac OS X, Safari on macOS Big Sur, Safari on iOS 14.0+ ),\n * **android-safetynet** (Chrome 70+, Firefox 68+)\n * **NFC devices using PCSC** (Not Tested, but as supported in fido2)\n\nIn English :), It allows you to verify the user by security keys on PC, Laptops or Mobiles, Windows Hello (Fingerprint, PIN) on Windows 10 Build 1903+ (May 2019 Update) Touch/Face ID on Macbooks (Chrome, Safari), Touch/Face ID on iPhone and iPad and Fingerprint/Face/Iris/PIN on Android Phones.\n\nTrusted device is a mode for the user to add a device that doesn't support security keys like Android without fingerprints or NFC.\n\n**Note**: `U2F and FIDO2 can only be served under secure context (https)`\n\nPackage tested with Django 1.8, Django 2.2 on Python 2.7 and Python 3.5+ but it was not checked with any version in between but open for issues.\n\nDepends on\n\n* pyotp\n* python-u2flib-server\n* ua-parser\n* user-agents\n* python-jose\n* fido2==0.9.0\n\n# Installation\n1. using pip \n\n `pip install django-mfa2`\n2. Using Conda forge \n \n `conda config --add channels conda-forge`\n \n `conda install django-mfa2`\n \n For more info, see the conda-forge repo (https://github.com/conda-forge/django-mfa2-feedstock)\n \n Thanks for [swainn](https://github.com/swainn) for adding package to conda-forge\n\n# Usage\n1. in your settings.py add the application to your installed apps\n ```python\n INSTALLED_APPS=(\n '......',\n 'mfa',\n '......')\n ```\n2. Collect Static Files\n`python manage.py collectstatic`\n3. Add the following settings to your file\n\n ```python \n MFA_UNALLOWED_METHODS=() # Methods that shouldn't be allowed for the user\n MFA_LOGIN_CALLBACK=\"\" # A function that should be called by username to login the user in session\n MFA_RECHECK=True # Allow random rechecking of the user\n MFA_REDIRECT_AFTER_REGISTRATION=\"mfa_home\" # Allows Changing the page after successful registeration\n MFA_SUCCESS_REGISTRATION_MSG = \"Go to Security Home\" # The text of the link\n MFA_RECHECK_MIN=10 # Minimum interval in seconds\n MFA_RECHECK_MAX=30 # Maximum in seconds\n MFA_QUICKLOGIN=True # Allow quick login for returning users by provide only their 2FA\n MFA_HIDE_DISABLE=('FIDO2',) # Can the user disable his key (Added in 1.2.0).\n MFA_OWNED_BY_ENTERPRISE = FALSE # Who owns security keys \n\n TOKEN_ISSUER_NAME=\"PROJECT_NAME\" #TOTP Issuer name\n\n U2F_APPID=\"https://localhost\" #URL For U2F\n FIDO_SERVER_ID=u\"localehost\" # Server rp id for FIDO2, it the full domain of your project\n FIDO_SERVER_NAME=u\"PROJECT_NAME\"\n FIDO_LOGIN_URL=BASE_URL\n ```\n **Method Names**\n * U2F\n * FIDO2\n * TOTP\n * Trusted_Devices\n * Email\n \n **Notes**:\n * Starting version 1.1, ~~FIDO_LOGIN_URL~~ isn't required for FIDO2 anymore.\n * Starting version 1.7.0, Key owners can be specified.\n * Starting version 2.2.0\n * Added: `MFA_SUCCESS_REGISTRATION_MSG` & `MFA_REDIRECT_AFTER_REGISTRATION`\n4. Break your login function\n\n Usually your login function will check for username and password, log the user in if the username and password are correct and create the user session, to support mfa, this has to change\n \n * authenticate the user\n * if username and password are correct , check if the user has mfa or not\n * if user has mfa then redirect to mfa page\n * if user doesn't have mfa then call your function to create the user session\n\n ```python\n def login(request): # this function handles the login form POST\n user = auth.authenticate(username=username, password=password) \n if user is not None: # if the user object exist\n from mfa.helpers import has_mfa\n res = has_mfa(username = username,request=request) # has_mfa returns false or HttpResponseRedirect\n if res:\n return res\n return log_user_in(request,username=user.username) \n #log_user_in is a function that handles creatung user session, it should be in the setting file as MFA_CALLBACK\n ```\n5. Add mfa to urls.py\n ```python \n import mfa\n import mfa.TrustedDevice\n urls_patterns= [\n '...',\n url(r'^mfa/', include('mfa.urls')),\n url(r'devices/add$', mfa.TrustedDevice.add,name=\"mfa_add_new_trusted_device\"), # This short link to add new trusted device\n '....',\n ]\n ```\n6. Provide `mfa_auth_base.html` in your templates with block called 'head' and 'content', The template will be included during the user login, the template shall be close to the login template.\n If you will use Email Token method, then you have to provide template named `mfa_email_token_template.html` that will content the format of the email with parameter named `user` and `otp`.\n7. To match the look and feel of your project, MFA includes `base.html` but it needs blocks named `head` & `content` to added its content to it.\n **Note:** Starting v2.3.0, a new template `mfa_base.html` is introduced, this template is used by `MFA.html` so you can control the styling better and current `mfa_base.html` extends `base.html`\n8. Somewhere in your app, add a link to 'mfa_home'\n```