### Install pyjwt-key-fetcher Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Install the package using pip. ```bash pip install pyjwt-key-fetcher ``` -------------------------------- ### Async JWT Verification Example Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Demonstrates fetching JWKs asynchronously and verifying a JWT token using PyJWT. Ensure the token and audience are correct for your use case. ```python import asyncio import jwt from pyjwt_key_fetcher import AsyncKeyFetcher async def main(): fetcher = AsyncKeyFetcher() # Token and options copied from # https://pyjwt.readthedocs.io/en/2.6.0/usage.html#retrieve-rsa-signing-keys-from-a-jwks-endpoint token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5FRTFRVVJCT1RNNE16STVSa0ZETlRZeE9UVTFNRGcyT0Rnd1EwVXpNVGsxUWpZeVJrUkZRdyJ9.eyJpc3MiOiJodHRwczovL2Rldi04N2V2eDlydS5hdXRoMC5jb20vIiwic3ViIjoiYVc0Q2NhNzl4UmVMV1V6MGFFMkg2a0QwTzNjWEJWdENAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vZXhwZW5zZXMtYXBpIiwiaWF0IjoxNTcyMDA2OTU0LCJleHAiOjE1NzIwMDY5NjQsImF6cCI6ImFXNENjYTc5eFJlTFdVejBhRTJINmtEME8zY1hCVnRDIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.PUxE7xn52aTCohGiWoSdMBZGiYAHwE5FYie0Y1qUT68IHSTXwXVd6hn02HTah6epvHHVKA2FqcFZ4GGv5VTHEvYpeggiiZMgbxFrmTEY0csL6VNkX1eaJGcuehwQCRBKRLL3zKmA5IKGy5GeUnIbpPHLHDxr-GXvgFzsdsyWlVQvPX2xjeaQ217r2PtxDeqjlf66UYl6oY6AqNS8DH3iryCvIfCcybRZkc_hdy-6ZMoKT6Piijvk_aXdm7-QQqKJFHLuEqrVSOuBqqiNfVrG27QzAPuPOxvfXTVLXL2jek5meH6n-VWgrBdoMFH93QEszEDowDAEhQPHVs0xj7SIzA" key_entry = await fetcher.get_key(token) token = jwt.decode( jwt=token, options={"verify_exp": False}, audience="https://expenses-api", **key_entry ) print(token) if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### AsyncKeyFetcher with Custom Configuration Path Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Override the default path for loading issuer configuration. This is useful when the configuration is not located at the standard '.well-known/openid-configuration'. ```python AsyncKeyFetcher(config_path="/.well-known/dataspace/party-configuration.json") ``` -------------------------------- ### Implement Custom HTTP Client Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Create a custom HTTP client by inheriting from `HTTPClient` and implementing an async function to fetch JSON from a URL. This allows for custom fetching logic beyond the default `aiohttp` client. ```python class CustomHTTPClient(HTTPClient): async def fetch_json(self, url: str) -> dict: # Implement custom logic here pass ``` -------------------------------- ### Configure Static Issuer Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Use this when an issuer does not provide an OpenID configuration. Specify the `jwks_uri` directly in the static configuration. ```python AsyncKeyFetcher( static_issuer_config={ "https://example.com": { "jwks_uri": "https://example.com/.well-known/jwks.json", }, }, ) ``` -------------------------------- ### AsyncKeyFetcher with Valid Issuers Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Limit the issuers from which keys can be fetched by providing a list of valid issuers during initialization. ```python AsyncKeyFetcher(valid_issuers=["https://example.com"]) ``` -------------------------------- ### AsyncKeyFetcher with Custom Cache Settings Source: https://github.com/ioxiocom/pyjwt-key-fetcher/blob/main/README.md Adjust the cache size and time-to-live (TTL) for fetched JWK data. This controls how long data for different issuers is cached and how often re-fetches occur. ```python AsyncKeyFetcher(cache_maxsize=10, cache_ttl=2*60*60) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.