Skip to main content

Django backends for AWS Cognito JWT

Project description

https://github.com/bekindsoft/django-cognito-jwt2/workflows/Python%20Tests/badge.svg http://codecov.io/github/LabD/django-cognito-jwt/coverage.svg?branch=master https://img.shields.io/pypi/v/django-cognito-jwt2.svg Documentation Status

Django Cognito JWT2

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

Installation

pip install django-cognito-jwt2

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_jwt2.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

django-cognito-jwt2-0.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cognito_jwt2-0.2.0-py2.py3-none-any.whl (5.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-cognito-jwt2-0.2.0.tar.gz.

File metadata

  • Download URL: django-cognito-jwt2-0.2.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django-cognito-jwt2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1ec9f4c77454bd259074465831a232273c42916f2e2006e366c7ca9cdecd062b
MD5 d3b1d53e1e0fab76ac839336b7b50d80
BLAKE2b-256 764d303dfc0ef42d718a014265d5d93eb501b04c751dfaa9dd70ce8364466c67

See more details on using hashes here.

Provenance

The following attestation bundles were made for django-cognito-jwt2-0.2.0.tar.gz:

Publisher: python-release.yml on bekindsoft/django-cognito-jwt2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_cognito_jwt2-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_cognito_jwt2-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e7f791129b9c1fa6b00a009641c0e687e45df275afa4acaa4bce0aff0de1749
MD5 46d45af257c8e78402379d7e216fc9d1
BLAKE2b-256 31fd37906741b53e96995e29b501ba123457e07534a66bf5dabfd8e305d2e13d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_cognito_jwt2-0.2.0-py2.py3-none-any.whl:

Publisher: python-release.yml on bekindsoft/django-cognito-jwt2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page