+
    ~j$                        ^ RI Ht ^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^ RIHt ^RIHtHt ^R	IHt ^R
IHtHt ^RIHt  ! R R4      tR# )    )annotationsN)	lru_cache)
SSLContext)Any)	HTTPErrorURLError)urlparse)PyJWKPyJWKSet)decode_complete)PyJWKClientConnectionErrorPyJWKClientError)JWKSetCachec                      ] tR t^tRR R lltR R ltRR R lltRR R	 lltR
 R ltR R lt	]
R R l4       tRtR# )PyJWKClientNc               8    V ^8  d   QhRRRRRRRRRR	R
RRR	RR/# )   uristr
cache_keysboolmax_cached_keysintcache_jwk_setlifespanfloatheaderszdict[str, Any] | Nonetimeoutssl_contextzSSLContext | None )formats   "d/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/jwt/jwks_client.py__annotate__PyJWKClient.__annotate__   sd     V3 V3V3 V3 	V3
 V3 V3 'V3 V3 'V3    c	                   Vf   / p\        V4      P                  P                  4       p	V	R9  d   \        RV	: R24      hWn        RV n        W`n        Wpn        Wn        V'       d(   V^ 8:  d   \        RV R24      h\        V4      V n        MRV n        V'       d%   \        VR7      ! V P                  4      p
Wn        R# R# )u  A client for retrieving signing keys from a JWKS endpoint.

``PyJWKClient`` uses a two-tier caching system to avoid unnecessary
network requests:

**Tier 1 — JWK Set cache** (enabled by default):
Caches the entire JSON Web Key Set response from the endpoint.
Controlled by:

- ``cache_jwk_set``: Set to ``True`` (the default) to enable this
  cache. When enabled, the JWK Set is fetched from the network only
  when the cache is empty or expired.
- ``lifespan``: Time in seconds before the cached JWK Set expires.
  Defaults to ``300`` (5 minutes). Must be greater than 0.

**Tier 2 — Signing key cache** (disabled by default):
Caches individual signing keys (looked up by ``kid``) using an LRU
cache with **no time-based expiration**. Keys are evicted only when
the cache reaches its maximum size. Controlled by:

- ``cache_keys``: Set to ``True`` to enable this cache.
  Defaults to ``False``.
- ``max_cached_keys``: Maximum number of signing keys to keep in
  the LRU cache. Defaults to ``16``.

:param uri: The URL of the JWKS endpoint.
:type uri: str
:param cache_keys: Enable the per-key LRU cache (Tier 2).
:type cache_keys: bool
:param max_cached_keys: Max entries in the signing key LRU cache.
:type max_cached_keys: int
:param cache_jwk_set: Enable the JWK Set response cache (Tier 1).
:type cache_jwk_set: bool
:param lifespan: TTL in seconds for the JWK Set cache.
:type lifespan: float
:param headers: Optional HTTP headers to include in requests.
:type headers: dict or None
:param timeout: HTTP request timeout in seconds.
:type timeout: float
:param ssl_context: Optional SSL context for the request.
:type ssl_context: ssl.SSLContext or None
NzInvalid JWKS URI scheme z(: only 'http' and 'https' are supported.z/Lifespan must be greater than 0, the input is "")maxsize)httphttps)r	   schemelowerr   r   jwk_set_cacher   r   r   r   r   get_signing_key)selfr   r   r   r   r   r   r   r   r+   r.   s   &&&&&&&&&  r"   __init__PyJWKClient.__init__   s    j ?G
 #%%++-**"*6* 5! "  15& 1}&EhZqQ  "-X!6D!%D'@AUAUVO#2 	 r%   c                   V ^8  d   QhRR/# )r   returnr   r    )r!   s   "r"   r#   r$   j   s      C r%   c                @    \         P                  P                  V P                  V P                  R7      p\         P                  P                  WP                  V P                  R7      ;_uu_ 4       p\        P                  ! V4      pRRR4       T P                   e   T P                   P#                  X4       X#   + '       g   i     L;; i  \        \        3 d<   p\        T\        4      '       d   TP                  4        \        RT R24      ThRp?ii ; i)a5  Fetch the JWK Set from the JWKS endpoint.

Makes an HTTP request to the configured ``uri`` and returns the
parsed JSON response. If the JWK Set cache is enabled, the
response is stored in the cache.

:returns: The parsed JWK Set as a dictionary.
:raises PyJWKClientConnectionError: If the HTTP request fails.
)urlr   )r   contextNz'Fail to fetch data from the url, err: "r'   )urllibrequestRequestr   r   urlopenr   r   jsonloadr   TimeoutError
isinstancer   closer   r-   put)r/   rresponsejwk_setes   &    r"   
fetch_dataPyJWKClient.fetch_dataj   s    	&&488T\\&JA''<<1A1A (  ))H- )""7+#  ,' 	!Y''	,9!A>	s6   A2C 4B>C >C		C C D"6DDc                    V ^8  d   QhRRRR/# )r   refreshr   r3   r   r    )r!   s   "r"   r#   r$      s     ( (4 (H (r%   c                    RpV P                   e#   V'       g   V P                   P                  4       pVf   V P                  4       p\        V\        4      '       g   \        R4      h\        P                  ! V4      # )a  Return the JWK Set, using the cache when available.

:param refresh: Force a fresh fetch from the endpoint, bypassing
    the cache.
:type refresh: bool
:returns: The JWK Set.
:rtype: PyJWKSet
:raises PyJWKClientError: If the endpoint does not return a JSON
    object.
Nz.The JWKS endpoint did not return a JSON object)r-   getrE   r>   dictr   r   	from_dict)r/   rH   datas   && r"   get_jwk_setPyJWKClient.get_jwk_set   sf     )'%%))+D<??$D$%%"#STT!!$''r%   c                    V ^8  d   QhRRRR/# )r   rH   r   r3   list[PyJWK]r    )r!   s   "r"   r#   r$      s        r%   c                    V P                  V4      pVP                   Uu. uF,  pVP                  R9   g   K  VP                  '       g   K*  VNK.  	  ppV'       g   \	        R4      hV# u upi )a_  Return all signing keys from the JWK Set.

Filters the JWK Set to keys whose ``use`` is ``"sig"`` (or
unspecified) and that have a ``kid``.

:param refresh: Force a fresh fetch from the endpoint, bypassing
    the cache.
:type refresh: bool
:returns: A list of signing keys.
:rtype: list[PyJWK]
:raises PyJWKClientError: If no signing keys are found.
z2The JWKS endpoint did not contain any signing keys)sigN)rN   keyspublic_key_usekey_idr   )r/   rH   rC   jwk_set_keysigning_keyss   &&   r"   get_signing_keysPyJWKClient.get_signing_keys   st     ""7+  '||
+))]: ?J?Q?Q K+ 	 
 "#WXX
s   A)A)A)c                    V ^8  d   QhRRRR/# )r   kidr   r3   r
   r    )r!   s   "r"   r#   r$      s      3 5 r%   c                    V P                  4       pV P                  W!4      pV'       g;   V P                  RR7      pV P                  W!4      pV'       g   \        RV R24      hV# )aY  Return the signing key matching the given ``kid``.

If no match is found in the current JWK Set, the set is
refreshed from the endpoint and the lookup is retried once.

:param kid: The key ID to look up.
:type kid: str
:returns: The matching signing key.
:rtype: PyJWK
:raises PyJWKClientError: If no matching key is found after
    refreshing.
T)rH   z,Unable to find a signing key that matches: "r'   )rY   	match_kidr   )r/   r\   rX   signing_keys   &&  r"   r.   PyJWKClient.get_signing_key   sh     ,,.nn\7000>L..;K&B3%qI  r%   c                    V ^8  d   QhRRRR/# )r   tokenzstr | bytesr3   r
   r    )r!   s   "r"   r#   r$      s     7 7k 7e 7r%   c                r    \        VRR/R7      pVR,          pV P                  VP                  R4      4      # )a  Return the signing key for a JWT by reading its ``kid`` header.

Extracts the ``kid`` from the token's unverified header and
delegates to :meth:`get_signing_key`.

:param token: The encoded JWT.
:type token: str or bytes
:returns: The matching signing key.
:rtype: PyJWK
verify_signatureF)optionsheaderr\   )decode_tokenr.   rJ   )r/   rb   
unverifiedrf   s   &&  r"   get_signing_key_from_jwt$PyJWKClient.get_signing_key_from_jwt   s:     "%2De1LM
H%##FJJu$566r%   c               $    V ^8  d   QhRRRRRR/# )r   rX   rQ   r\   r   r3   zPyJWK | Noner    )r!   s   "r"   r#   r$      s!       # , r%   c                H    RpV  F  pVP                   V8X  g   K  Tp V# 	  V# )zFind a key in *signing_keys* that matches *kid*.

:param signing_keys: The list of keys to search.
:type signing_keys: list[PyJWK]
:param kid: The key ID to match.
:type kid: str
:returns: The matching key, or ``None`` if not found.
:rtype: PyJWK or None
N)rV   )rX   r\   r_   keys   &&  r"   r^   PyJWKClient.match_kid   s5     CzzS !  
 r%   )r.   r   r-   r   r   r   )F   Ti,  N   N)F)__name__
__module____qualname____firstlineno__r0   rE   rN   rY   r.   ri   staticmethodr^   __static_attributes__r    r%   r"   r   r      s6    V3p>(.287  r%   r   )
__future__r   r;   urllib.requestr7   	functoolsr   sslr   typingr   urllib.errorr   r   urllib.parser	   api_jwkr
   r   api_jwtr   rg   
exceptionsr   r   r-   r   r   r    r%   r"   <module>r      s5    "      , ! $ 4 D &e er%   