/django-cognito-jwt

An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens

Primary LanguagePythonMIT LicenseMIT

image

image

image

Documentation Status

Django Cognito JWT

An Authentication backend for Django Rest Framework for AWS Cognito JWT tokens

Installation

pip install django-cognito-jwt

Usage

Add the following lines to your Django settings.py file:

(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).

Also update the rest framework settings to use the correct authentication backend:

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.