Skip to main content

Django backends for AWS Cognito JWT

Project description

https://github.com/bekindsoft/django-cognito-jwt/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-jwt.svg Documentation Status

Django Cognito JWT

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_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

django-cognito-jwt2-0.1.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.1.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.1.0.tar.gz.

File metadata

  • Download URL: django-cognito-jwt2-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 31954b21111107161710f8808eb2379be5858256ee774c5825800ba5caf9f088
MD5 39511f84a9ffc644d730b97641e19b0a
BLAKE2b-256 e4422552c1d152879866d8c1db1ac0bff31436b13b2ac575d4f40d2914fa5903

See more details on using hashes here.

Provenance

The following attestation bundles were made for django-cognito-jwt2-0.1.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.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_cognito_jwt2-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45b100a4d7319c905c6d8201f46c777b4e53b9507bf7696a34d3cdc4da048e85
MD5 eb2ddb84f44717c3f2a2d278be612e71
BLAKE2b-256 4151c2f50c26ab54aa4f186fe7ebf3580fccd34db7aff7beb646b4f98d493814

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_cognito_jwt2-0.1.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