{"id":16417419,"url":"https://github.com/MetaMetricsInc/django-warrant","last_synced_at":"2025-10-26T20:30:36.359Z","repository":{"id":20170625,"uuid":"89007687","full_name":"MetaMetricsInc/django-warrant","owner":"MetaMetricsInc","description":"Django package that uses AWS Cognito and Warrant to create a Django backend and common views.","archived":false,"fork":false,"pushed_at":"2022-05-09T12:20:42.000Z","size":63,"stargazers_count":192,"open_issues_count":11,"forks_count":62,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-01-16T07:52:34.933Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MetaMetricsInc.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-21T17:22:23.000Z","updated_at":"2024-09-09T09:55:38.000Z","dependencies_parsed_at":"2022-07-23T15:02:15.156Z","dependency_job_id":null,"html_url":"https://github.com/MetaMetricsInc/django-warrant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMetricsInc%2Fdjango-warrant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMetricsInc%2Fdjango-warrant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMetricsInc%2Fdjango-warrant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMetricsInc%2Fdjango-warrant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MetaMetricsInc","download_url":"https://codeload.github.com/MetaMetricsInc/django-warrant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238394323,"owners_count":19464583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T07:11:30.018Z","updated_at":"2025-10-26T20:30:36.011Z","avatar_url":"https://github.com/MetaMetricsInc.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"## Django Warrant\n\n### Install\n\n`pip install django-warrant`\n\n### Django Auth Backend\n#### Using the CognitoBackend\n1. In your Django project settings file, add the dotted path of\n`CognitoBackend` to your list of `AUTHENTICATION_BACKENDS`.\nKeep in mind that Django will attempt to authenticate a user using\neach backend listed, in the order listed until successful.\n\n    ```python\n    AUTHENTICATION_BACKENDS = [\n        'django_warrant.backend.CognitoBackend',\n        ...\n    ]\n    ```\n2. Set `COGNITO_USER_POOL_ID` and `COGNITO_APP_ID` in your settings file as well.\nYour User Pool ID can be found in the Pool Details tab in the AWS console.\nYour App ID is found in the Apps tab, listed as \"App client id\".\n\n3. Set `COGNITO_ATTR_MAPPING` in your settings file to a dictionary mapping a\nCognito attribute name to a Django User attribute name.\nIf your Cognito User Pool has any custom attributes, it is automatically\nprefixed with `custom:`. Therefore, you will want to add a mapping to your\nmapping dictionary as such `{'custom:custom_attr': 'custom_attr'}`.\nDefaults to:\n    ```python\n    {\n        'email': 'email',\n        'given_name': 'first_name',\n        'family_name': 'last_name',\n    }\n    ```\n4. Optional - Set `COGNITO_CREATE_UNKNOWN_USERS` to `True` or `False`, depending on if\nyou wish local Django users to be created upon successful login. If set to `False`,\nonly existing local Django users are updated.\nDefaults to `True`.\n\n5. Optional - Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`\nto the AWS access keys you would like to use.\nDefaults to `None`, which will use the default credentials in your `~/.aws/credentials` file.\n\n#### CognitoBackend Behavior\nSince the username of a Cognito User can never change,\nthis is used by the backend to match a Cognito User with a local Django\nUser.\n\nIf a Django user is not found, one is created using the attributes\nfetched from Cognito. If an existing Django user is found, their\nattributes are updated.\n\nIf the boto3 client comes back with either a `NotAuthorizedException` or\n`UserNotFoundException`, then `None` is returned instead of a User.\nOtherwise, the exception is raised.\n\nUpon successful login, the three identity tokens returned from Cognito\n(ID token, Refresh token, Access token) are stored in the user's request\nsession. In Django \u003e= 1.11, this is done directly in the backend class.\nOtherwise, this is done via the `user_logged_in` signal.\n\nCheck the cdu directory for an example app with a login and\nuser details page.\n\n#### Customizing CognitoBackend Behavior\nSetting the Django setting `COGNITO_CREATE_UNKNOWN_USERS` to `False` prevents the backend\nfrom creating a new local Django user and only updates existing users.\n\nIf you create your own backend class that inhereits from `CognitoBackend`, you may\nwant to also create your own custom `user_logged_in` so that it checks\nfor the name of your custom class.\n\n### API Gateway Integration\n\n#### API Key Middleware\nThe `APIKeyMiddleware` checks for a `HTTP_AUTHORIZATION_ID` header\nin the request and attaches it to the request object as `api_key`.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMetaMetricsInc%2Fdjango-warrant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMetaMetricsInc%2Fdjango-warrant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMetaMetricsInc%2Fdjango-warrant/lists"}