Django backends for AWS Cognito JWT
Project description
An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens
Status
Installation
pip install django-cognito-jwt
Usage
Add the following lines to your Django settings.py file:
COGNITO_AWS_REGION = '<aws region>' # 'eu-central-1'
COGNITO_USER_POOL = '<user pool>' # 'eu-central-1_xYzaq'
COGNITO_AUDIENCE = '<client id>'
(Optional) If you want to cache the Cognito public keys between requests you can enable the COGNITO_PUBLIC_KEYS_CACHING_ENABLED setting (it only works if you have the Django CACHES setup to anything other than the dummy backend).
COGNITO_PUBLIC_KEYS_CACHING_ENABLED = True
COGNITO_PUBLIC_KEYS_CACHING_TIMEOUT = 60*60*24 # 24h caching, default is 300s
Also update the rest framework settings to use the correct authentication backend:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'django_cognito_jwt.JSONWebTokenAuthentication',
...
],
...
}
Be sure you are passing the ID Token JWT from Cognito as the authentication header. Using the Access Token will work for authentication only but we’re unable to use the get_or_create_for_cognito method with the Access Token.
(Optional) If you want to use a different user model then the default DJANGO_USER_MODEL you can use the COGNITO_USER_MODEL setting.
COGNITO_USER_MODEL = "myproject.AppUser"
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 django_cognito_jwt-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ebc75725042bf1c6b09defef01b413c136a0897c8f3ad5433b550fa691fa8a3 |
|
MD5 | 2e8edd568f52d620ea36ed3c31bc396b |
|
BLAKE2b-256 | 46e95870eb6ce71b40b28487f033ac05c93a8305ed8b3594136f42dcd6354149 |