Reusable Django app for Penn Labs accounts
Project description
Django Labs Accounts
Requirements
- Python 3.5+
- Django 2.1+
Installation
Install with pip pip install django-labs-accounts
Add accounts to INSTALLED_APPS
INSTALLED_APPS = (
...
'accounts.apps.AccountsConfig',
...
)
Add the new accounts backend to AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
...
'accounts.backends.LabsUserBackend',
'django.contrib.auth.backends.ModelBackend',
...
)
Add the new accounts middleware to MIDDLEWARE. Note the middleware does not need to be at the top of the list, but should be placed above the default Django middleware.
MIDDLEWARE = [
...
'accounts.middleware.OAuth2TokenMiddleware',
...
]
Add the following to urls.py
urlpatterns = [
...
path('accounts/', include('accounts.urls', namespace='accounts')),
...
]
Documentation
All settings are handled within a PLATFORM_ACCOUNTS dictionary.
Example:
PLATFORM_ACCOUNTS = {
'CLIENT_ID': 'id',
'CLIENT_SECRET': 'secret',
'REDIRECT_URI': 'example',
'ADMIN_PERMISSION': 'example_admin'
'CUSTOM_ADMIN': True
}
The available settings are:
CLIENT_ID the client ID to connect to platform with. Defaults to LABS_CLIENT_ID environment variable.
CLIENT_SECRET the client secret to connect to platform with. Defaults to LABS_CLIENT_SECRET environment variable.
REDIRECT_URI the redirect uri to send to platform. Defaults to LABS_REDIRECT_URI environment variable.
SCOPE the scope for this applications tokens. Must include introspection. Defaults to ['read', 'introspection'].
PLATFORM_URL URL of platform server to connect to. Should be https://platform(-dev).pennlabs.org (no trailing slash)
ADMIN_PERMISSION The name of the permission on platform to grant admin access. Defaults to example_admin
CUSTOM_ADMIN enable the custom admin login page to log in users through platform. Defaults to True
When developing locally with an http (not https) callback URL, it may be helpful to set the OAUTHLIB_INSECURE_TRANSPORT environment variable.
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = "1"
Custom post authentication
If you want to customize how DLA saves user information from platform into User objects, you can subclass accounts.backends.LabsUserBackend and redefine the post_authenticate method. This method will be run after the user is logged in. The parameters are:
userthe user objectcreateda boolean delineating if the user was just createddictionarya dictionary of user information from platform.
Then just set the AUTHENTICATION_BACKENDS setting to be the subclassed backend.
Here is an example of a custom backend that sets every user's first name to "Modified".
from accounts.backends import LabsUserBackend
class CustomBackend(LabsUserBackend):
def post_authenticate(self, user, created, dictionary):
user.first_name = 'Modified'
user.save()
Changelog
See CHANGELOG.md
License
See LICENSE.md
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-labs-accounts-0.5.2.tar.gz.
File metadata
- Download URL: django-labs-accounts-0.5.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.41.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35bc0158892d410e84faf5f6e0619641beb5dd934a29fc5749e4bc2421b50118
|
|
| MD5 |
e18a8d4d8decd5e97612686016b3c2fe
|
|
| BLAKE2b-256 |
bf4990fe93a5268199398a826527186b549ac115487a77b782ea52f5558c47cc
|
File details
Details for the file django_labs_accounts-0.5.2-py3-none-any.whl.
File metadata
- Download URL: django_labs_accounts-0.5.2-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.41.0 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
877665eed4760d3cd6864b4d80cd9ba7bc1294dab8ac67ff04e4ec4f1cb08672
|
|
| MD5 |
aa6c9240f4aa300f1ce3e0f2d7eb50f4
|
|
| BLAKE2b-256 |
dbadaac0bb55f2a9d9d85e2cf367635d2242597e5b31ebaf2d12382ee4b1940d
|