Skip to main content

Tools for Azure Actve Directory JWT tokens

Project description

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.

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:

import jwt

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

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

azjwt-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file azjwt-0.1.1.tar.gz.

File metadata

  • Download URL: azjwt-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.6

File hashes

Hashes for azjwt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be1b50c061fb33d9791f31dd784eda6ccc7ddd4727d87372db96f54ed518c7ea
MD5 98539e0b5e56979435fc6b454218bb0e
BLAKE2b-256 686d617945e9b02935d39b06f9a41d10992d6ac51c188a62fafedf16d835905f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page