cognitojwt


Namecognitojwt JSON
Version 1.5.0 PyPI version JSON
download
home_pagehttp://github.com/borisrozumnuk/cognitojwt
SummaryDecode and verify Amazon Cognito JWT tokens
upload_time2024-04-19 10:59:56
maintainerNone
docs_urlNone
authorBoris Rozumniuk
requires_pythonNone
licenseMIT
keywords amazon cognito jwt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            [![Build Status](https://travis-ci.org/borisrozumnuk/cognitojwt.svg?branch=master)](https://travis-ci.org/borisrozumnuk/cognitojwt)

# Decode and verify [Amazon Cognito](https://aws.amazon.com/cognito/) JWT tokens

### Note: tested on Python >= 3.6, compatible with PEP-492 (async/await coroutines syntax)

### Installation

Package works in two modes: synchronous - [requests](https://github.com/requests/requests) as http-client and asynchronous - [aiohttp](https://github.com/aio-libs/aiohttp) as http-client.
In order to avoid installing unnecessary dependencies I separated installation flow into two modes:

* Async mode - `pip install cognitojwt[async]`
* Sync mode - `pip install cognitojwt[sync]`

### Usage

```python
import cognitojwt

id_token = '<YOUR_TOKEN_HERE>'
REGION = '**-****-*'
USERPOOL_ID = 'eu-west-1_*******'
APP_CLIENT_ID = '1p3*********'

# Sync mode
verified_claims: dict = cognitojwt.decode(
    id_token,
    REGION,
    USERPOOL_ID,
    app_client_id=APP_CLIENT_ID,  # Optional
    testmode=True  # Disable token expiration check for testing purposes
)

# Async mode
verified_claims: dict = await cognitojwt.decode_async(
    id_token,
    REGION,
    USERPOOL_ID,
    app_client_id=APP_CLIENT_ID,  # Optional
    testmode=True  # Disable token expiration check for testing purposes
)

```

Note: if the application is deployed inside a private vpc without internet gateway, the application will not be able to download the JWKS file.
In this case set the `AWS_COGNITO_JWKS_PATH` environment variable referencing the absolute or relative path of the jwks.json file.

It is possible to allow multiple app client ids by passing the value as a Container instance such as a list or tuple:
```python
ALLOWED_CLIENT_IDS = ('client_one', 'client_two')

verified_claims: dict = cognitojwt.decode(
    id_token,
    REGION,
    USERPOOL_ID,
    app_client_id=ALLOWED_CLIENT_IDS,
    testmode=True  # Disable token expiration check for testing purposes
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/borisrozumnuk/cognitojwt",
    "name": "cognitojwt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Amazon Cognito JWT",
    "author": "Boris Rozumniuk",
    "author_email": "borisrozumnuk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e2/08/ef441da11cc3815a899c65f6416caa73472b6de435ba18dca54924707e9d/cognitojwt-1.5.0.tar.gz",
    "platform": "Any",
    "description": "[![Build Status](https://travis-ci.org/borisrozumnuk/cognitojwt.svg?branch=master)](https://travis-ci.org/borisrozumnuk/cognitojwt)\n\n# Decode and verify [Amazon Cognito](https://aws.amazon.com/cognito/) JWT tokens\n\n### Note: tested on Python >= 3.6, compatible with PEP-492 (async/await coroutines syntax)\n\n### Installation\n\nPackage works in two modes: synchronous - [requests](https://github.com/requests/requests) as http-client and asynchronous - [aiohttp](https://github.com/aio-libs/aiohttp) as http-client.\nIn order to avoid installing unnecessary dependencies I separated installation flow into two modes:\n\n* Async mode - `pip install cognitojwt[async]`\n* Sync mode - `pip install cognitojwt[sync]`\n\n### Usage\n\n```python\nimport cognitojwt\n\nid_token = '<YOUR_TOKEN_HERE>'\nREGION = '**-****-*'\nUSERPOOL_ID = 'eu-west-1_*******'\nAPP_CLIENT_ID = '1p3*********'\n\n# Sync mode\nverified_claims: dict = cognitojwt.decode(\n    id_token,\n    REGION,\n    USERPOOL_ID,\n    app_client_id=APP_CLIENT_ID,  # Optional\n    testmode=True  # Disable token expiration check for testing purposes\n)\n\n# Async mode\nverified_claims: dict = await cognitojwt.decode_async(\n    id_token,\n    REGION,\n    USERPOOL_ID,\n    app_client_id=APP_CLIENT_ID,  # Optional\n    testmode=True  # Disable token expiration check for testing purposes\n)\n\n```\n\nNote: if the application is deployed inside a private vpc without internet gateway, the application will not be able to download the JWKS file.\nIn this case set the `AWS_COGNITO_JWKS_PATH` environment variable referencing the absolute or relative path of the jwks.json file.\n\nIt is possible to allow multiple app client ids by passing the value as a Container instance such as a list or tuple:\n```python\nALLOWED_CLIENT_IDS = ('client_one', 'client_two')\n\nverified_claims: dict = cognitojwt.decode(\n    id_token,\n    REGION,\n    USERPOOL_ID,\n    app_client_id=ALLOWED_CLIENT_IDS,\n    testmode=True  # Disable token expiration check for testing purposes\n)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Decode and verify Amazon Cognito JWT tokens",
    "version": "1.5.0",
    "project_urls": {
        "Homepage": "http://github.com/borisrozumnuk/cognitojwt"
    },
    "split_keywords": [
        "amazon",
        "cognito",
        "jwt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "afa06d90b549a6c072886c1689763ec9a1e8077b7f673f0ffdc4d18bfbd788fa",
                "md5": "3de4e3079644a3765e1e8cbd0bbfaffd",
                "sha256": "758bbec4e66757e023d29728ed09fef4420e032cc414871d9fb1b47456d850a3"
            },
            "downloads": -1,
            "filename": "cognitojwt-1.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3de4e3079644a3765e1e8cbd0bbfaffd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6552,
            "upload_time": "2024-04-19T10:59:54",
            "upload_time_iso_8601": "2024-04-19T10:59:54.872968Z",
            "url": "https://files.pythonhosted.org/packages/af/a0/6d90b549a6c072886c1689763ec9a1e8077b7f673f0ffdc4d18bfbd788fa/cognitojwt-1.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e208ef441da11cc3815a899c65f6416caa73472b6de435ba18dca54924707e9d",
                "md5": "4529eb1314c84faf92f4a19152df55d0",
                "sha256": "cc22236f86097f9dfd4501cf0b8a3ff8f2e69a3953236de4e43d2f7419367c4d"
            },
            "downloads": -1,
            "filename": "cognitojwt-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4529eb1314c84faf92f4a19152df55d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5753,
            "upload_time": "2024-04-19T10:59:56",
            "upload_time_iso_8601": "2024-04-19T10:59:56.004467Z",
            "url": "https://files.pythonhosted.org/packages/e2/08/ef441da11cc3815a899c65f6416caa73472b6de435ba18dca54924707e9d/cognitojwt-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-19 10:59:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "borisrozumnuk",
    "github_project": "cognitojwt",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cognitojwt"
}
        
Elapsed time: 0.23160s