Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/labd/django-cognito-jwt
An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens
https://github.com/labd/django-cognito-jwt
aws cognito
Last synced: 2 days ago
JSON representation
An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens
- Host: GitHub
- URL: https://github.com/labd/django-cognito-jwt
- Owner: labd
- License: mit
- Created: 2018-01-19T10:32:25.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T16:46:45.000Z (7 months ago)
- Last Synced: 2025-01-18T02:09:25.675Z (9 days ago)
- Topics: aws, cognito
- Language: Python
- Homepage:
- Size: 59.6 KB
- Stars: 178
- Watchers: 11
- Forks: 58
- Open Issues: 18
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES
- License: LICENSE
Awesome Lists containing this project
README
.. start-no-pypi
.. image:: https://github.com/labd/django-cognito-jwt/workflows/Python%20Tests/badge.svg
:target: https://github.com/labd/django-cognito-jwt/workflows/Python%20Tests/.. image:: http://codecov.io/github/LabD/django-cognito-jwt/coverage.svg?branch=master
:target: http://codecov.io/github/LabD/django-cognito-jwt?branch=master.. image:: https://img.shields.io/pypi/v/django-cognito-jwt.svg
:target: https://pypi.python.org/pypi/django-cognito-jwt/.. image:: https://readthedocs.org/projects/django-cognito-jwt/badge/?version=latest
:target: https://django-cognito-jwt.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. end-no-pypiDjango Cognito JWT
==================An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens
Installation
============.. code-block:: shell
pip install django-cognito-jwt
Usage
=====Add the following lines to your Django ``settings.py`` file:
.. code-block:: python
COGNITO_AWS_REGION = '' # 'eu-central-1'
COGNITO_USER_POOL = '' # 'eu-central-1_xYzaq'
COGNITO_AUDIENCE = ''(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)... code-block:: python
COGNITO_PUBLIC_KEYS_CACHING_ENABLED = True
COGNITO_PUBLIC_KEYS_CACHING_TIMEOUT = 60*60*24 # 24h caching, default is 300sAlso update the rest framework settings to use the correct authentication backend:
.. code-block:: python
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... code-block:: python
COGNITO_USER_MODEL = "myproject.AppUser"