Authenticated users using Auth0.
Project description
Django Auth0 Auth
Django Auth0 Auth allows you to authenticate through Auth0 in Django 2
Installation
Run pip install django2-auth0-auth
Add the Auth0Backend
to your AUTHENTICATION_BACKENDS
setting:
AUTHENTICATION_BACKENDS = (
...
'auth0_auth.backends.Auth0Backend',
)
Edit your urls.py
to include:
urlpatterns = [
url(r'^auth0/', include('auth0_auth.urls')),
...
]
Settings
AUTH0_DOMAIN
Auth0 domain.
AUTH0_CLIENT_ID
Auth0 client id.
AUTH0_CLIENT_SECRET
Auth0 client secret.
AUTH0_SECRET_BASE64_ENCODED
default: False
Flag if Auth0 client secret is base64 encoded.
AUTH0_SCOPE
default: 'openid email'
OAuth scope parameter.
AUTH0_RESPONSE_TYPE
default: 'token'
OAuth response type parameter.
AUTH0_USER_CREATION
default: True
Allow creation of new users after successful authentication.
Lock Signin
To log in using the JavaScript based Lock dialog, add the following to your project.
Add the auth0
context processor to the TEMPLATES
options.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'OPTIONS': {
'context_processors': [
...
'auth0_auth.context_processors.auth0',
],
},
},
]
Add the following JavaScript snippet to your extrahead
block where you'd like the login to appear.
{% block extrahead %}
<script src="https://cdn.auth0.com/js/lock/11.14/lock.min.js"></script>
<script type="text/javascript">
var lock = new Auth0Lock('{{ AUTH0_CLIENT_ID }}', '{{ AUTH0_DOMAIN }}');
function signin() {
lock.show({
callbackURL: '{{ AUTH0_CALLBACK_URL }}',
responseType: 'token',
authParams: {
'scope': '{{ AUTH0_SCOPE }}',
'response_mode': 'form_post',
'state': '{{ AUTH0_STATE }}'
}
});
}
</script>
{% endblock %}
Add a login button to the page.
<button onclick="window.signin();">Login</button>
Logging
To enable logging add auth0_auth
to LOGGING['loggers']
options.
LOGGING = {
...,
'loggers': {
...,
'auth0_auth': {
'handlers': ['console'],
'level': 'DEBUG',
}
}
}
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
Built Distribution
Hashes for django2_auth0_auth-4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e55e0b3729a3114449cb8c481f2118fe3d45aa6c567cc969756a0831451a831e |
|
MD5 | 047f04e826432dbae67f1f890dbc4439 |
|
BLAKE2b-256 | 14746194a2532989c5c1cc4aa128bd347b949caf9c45c13bb1db2d876a0d290d |