Core library for Nexus django applications that require User accounts
Project description
Core library for Nexus django applications that require User accounts
Documentation
The full documentation is at https://django-genomix-users.readthedocs.io.
Quickstart
Install Django GenomiX Users:
pip install django-genomix-users
Make the following changes to INSTALLED_APPS in settings.py file:
INSTALLED_APPS = (
...
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
...
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django_filters',
...
'django_python3_ldap',
...
'genomix_users',
...
)
Add Django GenomiX Users’s URL patterns:
from genomix_users import urls as genomix_users_urls
urlpatterns = [
...
url(r'^', include(genomix_users_urls, namespace='users')),
...
]
Make sure settings.py file has TEMPLATES and STATIC_URL set (example below):
TEMPLATES = [
{
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
'DIRS': [
os.path.join(ROOT_DIR, 'templates'),
os.path.join(APPS_DIR, 'templates'),
],
'OPTIONS': {
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
'debug': DEBUG,
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
# Your stuff: custom template context processors go here
],
},
},
]
STATIC_URL = '/static/'
Make sure settings.py file has MIDDLEWARE set (example below):
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Optional settings
Turn off the creation of associated user profiles in settings.py.
CREATE_PROFILE_ON_SAVE = False
Enable authentication to use JSON Web Token in settings.py:
REST_USE_JWT = True
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
Enable LDAP authentication in settings.py:
LDAP_AUTH_URL = 'ldap://chop.edu:3268'
LDAP_AUTH_USE_TLS = False
LDAP_AUTH_SEARCH_BASE = 'dc=chop,dc=edu'
LDAP_AUTH_OBJECT_CLASS = 'person'
LDAP_AUTH_USER_LOOKUP_FIELDS = ('username',)
LDAP_AUTH_USER_FIELDS = {
"username": "sAMAccountName",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
LDAP_AUTH_FORMAT_USERNAME = 'django_python3_ldap.utils.format_username_active_directory'
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = 'chop-edu'
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_python3_ldap.auth.LDAPBackend',
]
Enable LDAP User group filtering in settings.py:
LDAP_AUTH_FORMAT_SEARCH_FILTERS = 'genomix_users.authentication.genomix_search_filters'
LDAP_AUTH_SEARCH_FILTER = 'CN=dgd_nexus_users,ou=DGD Groups,ou=SecurityGroups,ou=Research,ou=Managed By Others,dc=chop,dc=edu'
Sync User Profile with LDAP fields in settings.py:
LDAP_AUTH_SYNC_USER_RELATIONS = "genomix_users.authentication.sync_genomix_profile"
# User model fields mapped to the LDAP attributes that represent them.
LDAP_AUTH_PROFILE_FIELDS = {
"title": "title",
}
Features
GenomiX REST API for authentication using django-rest-auth
GenomiX LDAP authentication using django-python3-ldap
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2017-12-03)
First release on PyPI.
Initial models and REST API.
0.2.0 (2017-12-11)
Added Profile.
Added ability to sync profile from LDAP.
0.3.0 (2017-01-05)
Added REST API filters.
0.3.1 (2017-01-12)
Fixed route names for SimpleRouter
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-genomix-users-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a24b5ccc21e939076d14875fa248ad99b4015b0d43ab607d261ff8c1f7b80297 |
|
MD5 | de1e23d6e9215d219534850bfb31b918 |
|
BLAKE2b-256 | 8b9294614ddf2b2aa5233c4c0e84fb12e88b4851390589a766dcf1f42bb81b6f |
Hashes for django_genomix_users-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bc95420abca1c4c4964d91764ec29f0e0e63987250bd66bcc4e37aa982f4a66 |
|
MD5 | 30e096829e9ad9ed704f3ba61e3e7456 |
|
BLAKE2b-256 | df94b0628a13ba25f2f11cc2b9ac0a03906706b69d6383367706bdfd9de9abd4 |