AWS Cognito code grant for Django Rest Framework
This package implements an authentication backend and a set of handlers that enable your application to use code grant authentication with AWS Cognito.
The package has been developed by STITCH (https://www.stitchdesignlab.com/)
The documentation for this project is a work-in-progress and is pretty much bare bones. Do not hesitate to contact us, or open an issue or PR for contribution.
Links
Code grant
Code grant is an OAuth 2.0 flow that allows one to use Cognito as a data store and authentication backend for users, while maintaining an updating replica of User and Group information in your applications database. This way, the application gains the possibility to add custom business logic for users, while the user data is still stored and managed centrally through Cognito.
This is especially useful when you are implementing multiple API backends for a platform that consist of multiple applications that need to operate on a shared userbase.
See the link above for a detailed explanation of the standard.
Installation
You can install this package from pip: pip install cognito_code_grant
Usage
The implementation consists of an authentication backend, a login handler, and a logout handler. To use the backend, simply specify it in your Django Settings:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'cognito_code_grant.authentication.CognitoAuthentication',
'rest_framework.authentication.BasicAuthentication',
...
)
To use the handlers, include them in your URLs using a helper function:
from cognito_code_grant.views import include_auth_urls
urlpatterns = [
path('auth/', include_auth_urls()),
...
]
Additionally, you will need to set the following settings to point to your instance of Cognito:
AUTH_COGNITO_CLIENT_ID = # your client ID
AUTH_COGNITO_CODE_GRANT_URL = # your token endpoint (https://AUTH_DOMAIN/oauth2/token)
AUTH_COGNITO_JWKS_URL = # the url for your JWKs (https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json.)
Development
To run tests, you need to point Django to local test settings, and run the migrations (it will use an sqllite db in a temp folder).
export DJANGO_SETTINGS_MODULE=tests.settings
python -m django migrate
python -m django test
On a merge to master, CICD will automatically create a patch version bump, and deploy to pypi. Minor/Major realeases need to be handled manually by the maintainers.
Metadata
Release files for cognito-code-grant 1.0.30
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cognito_code_grant-1.0.30.tar.gz | 7.1 kB | Without provenance | Details |
Release files / cognito_code_grant-1.0.30.tar.gz
| Download URL | cognito_code_grant-1.0.30.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2b58b0202b41472e9be0a6a7e55be8b6114b77973fb5016ff25c5641930a41f
|
|
BLAKE2b-256 checksum How to use checksums |
3c938f0bdf1b4e2d260833e35e8cdf19c710261435158325e7aec4eae70c81aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.0
|
Security for cognito-code-grant 1.0.30
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.