azjwt


Nameazjwt JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/ivangeorgiev/aad-jwt
SummaryTools for Azure Actve Directory JWT tokens
upload_time2023-05-05 16:52:15
maintainer
docs_urlNone
authorIvan Georgiev
requires_python
licenseCreative Commons
keywords authentication azure jwt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tools for Azure Active Directory JWT Tokens

## Example: OpenIdDiscovery to get a signature key

In this example we use the openid discovery metadata to find a signing public key for a tenant. Common scenario is a JWT signature validation.

```python
from azjwt import *
url = tenant_metadata_endpoint("3a15932d-3fd9-4278-a753-beb05cdf0c6d")
discovery = OpenIdDiscovery(url)
key = discovery.get_key("nOo3ZDrODABD1jKWhXslMN_KXEg")
rsa = jwk_to_rsa_pem(key)
print(rsa.decode())
```

The result of the execution of this code is a RSA key:

```
-----BEGIN PUBLIC KEY-----
MAABIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoaLLT9hkcSj2tGfZsjbu
7Xz1Krs0qEicXPmEsJKOBQHauZ/kRM1HdEkgOJbUznUspE6xOuOSXjlzErqBxXAu
4SCvcvVOCYG2v9G3+uIrLF5dstD0sYHBo1VomtKxzF90Vslrkn6rNQgUGIWgvuQT
xm1uRklYFPEcTMRw0LnYknzJ06GC9ljKR617wABVrZNkBuDgQKj37qcyxoaxIGdx
EcmVFZXJyrxDgdXh9owRmZn6LIJlGjZ9m59emfuwnBnsIQG7DirJwe9SXrLXnexR
QWqyzCdkYaOqkpKrsjuxUj2+MHX31FqsdpJJsOAvYXGOYBKJRjhGrGdONVrZdUdT
BQIDAQAB
-----END PUBLIC KEY-----
```

The key id (`kid`) could be obtained from the JWT token, using PyJWT package. Here is an example:

```python
import jwt

headers = jwt.get_unverified_headers(token)
key_id = headers["kid"]
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ivangeorgiev/aad-jwt",
    "name": "azjwt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "authentication,azure,jwt",
    "author": "Ivan Georgiev",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/68/6d/617945e9b02935d39b06f9a41d10992d6ac51c188a62fafedf16d835905f/azjwt-0.1.1.tar.gz",
    "platform": null,
    "description": "# Tools for Azure Active Directory JWT Tokens\n\n## Example: OpenIdDiscovery to get a signature key\n\nIn this example we use the openid discovery metadata to find a signing public key for a tenant. Common scenario is a JWT signature validation.\n\n```python\nfrom azjwt import *\nurl = tenant_metadata_endpoint(\"3a15932d-3fd9-4278-a753-beb05cdf0c6d\")\ndiscovery = OpenIdDiscovery(url)\nkey = discovery.get_key(\"nOo3ZDrODABD1jKWhXslMN_KXEg\")\nrsa = jwk_to_rsa_pem(key)\nprint(rsa.decode())\n```\n\nThe result of the execution of this code is a RSA key:\n\n```\n-----BEGIN PUBLIC KEY-----\nMAABIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoaLLT9hkcSj2tGfZsjbu\n7Xz1Krs0qEicXPmEsJKOBQHauZ/kRM1HdEkgOJbUznUspE6xOuOSXjlzErqBxXAu\n4SCvcvVOCYG2v9G3+uIrLF5dstD0sYHBo1VomtKxzF90Vslrkn6rNQgUGIWgvuQT\nxm1uRklYFPEcTMRw0LnYknzJ06GC9ljKR617wABVrZNkBuDgQKj37qcyxoaxIGdx\nEcmVFZXJyrxDgdXh9owRmZn6LIJlGjZ9m59emfuwnBnsIQG7DirJwe9SXrLXnexR\nQWqyzCdkYaOqkpKrsjuxUj2+MHX31FqsdpJJsOAvYXGOYBKJRjhGrGdONVrZdUdT\nBQIDAQAB\n-----END PUBLIC KEY-----\n```\n\nThe key id (`kid`) could be obtained from the JWT token, using PyJWT package. Here is an example:\n\n```python\nimport jwt\n\nheaders = jwt.get_unverified_headers(token)\nkey_id = headers[\"kid\"]\n```",
    "bugtrack_url": null,
    "license": "Creative Commons",
    "summary": "Tools for Azure Actve Directory JWT tokens",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/ivangeorgiev/aad-jwt"
    },
    "split_keywords": [
        "authentication",
        "azure",
        "jwt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "686d617945e9b02935d39b06f9a41d10992d6ac51c188a62fafedf16d835905f",
                "md5": "98539e0b5e56979435fc6b454218bb0e",
                "sha256": "be1b50c061fb33d9791f31dd784eda6ccc7ddd4727d87372db96f54ed518c7ea"
            },
            "downloads": -1,
            "filename": "azjwt-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "98539e0b5e56979435fc6b454218bb0e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4077,
            "upload_time": "2023-05-05T16:52:15",
            "upload_time_iso_8601": "2023-05-05T16:52:15.190561Z",
            "url": "https://files.pythonhosted.org/packages/68/6d/617945e9b02935d39b06f9a41d10992d6ac51c188a62fafedf16d835905f/azjwt-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-05 16:52:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ivangeorgiev",
    "github_project": "aad-jwt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "azjwt"
}
        
Elapsed time: 0.06168s