§
    !¾<i!  ã                   óv   — d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ  G d	„ d
e¦  «        ZdS )é    )ÚContinueIteration)Údefault_json_headers)ÚExpiredTokenError)ÚInvalidClaimError)ÚInvalidTokenError)ÚJWTBearerTokenValidatoré   )ÚIntrospectionEndpointc                   óP   ‡ — e Zd ZdZdZdˆ fd„	Zd„ Zd„ Zd„ Zd„ Z	d	e
d
e
fd„Zˆ xZS )ÚJWTIntrospectionEndpointað  JWTIntrospectionEndpoint inherits from :ref:`specs/rfc7662`
    :class:`~authlib.oauth2.rfc7662.IntrospectionEndpoint` and implements the machinery
    to automatically process the JWT access tokens.

    :param issuer: The issuer identifier for which tokens will be introspected.

    :param \\*\\*kwargs: Other parameters are inherited from
        :class:`~authlib.oauth2.rfc7662.introspection.IntrospectionEndpoint`.

    ::

        class MyJWTAccessTokenIntrospectionEndpoint(JWTIntrospectionEndpoint):
            def get_jwks(self): ...

            def get_username(self, user_id): ...


        # endpoint dedicated to JWT access token introspection
        authorization_server.register_endpoint(
            MyJWTAccessTokenIntrospectionEndpoint(
                issuer="https://authorization-server.example.org",
            )
        )

        # another endpoint dedicated to refresh token introspection
        authorization_server.register_endpoint(MyRefreshTokenIntrospectionEndpoint)

    ÚintrospectionNc                 óL   •—  t          ¦   «         j        |d|i|¤Ž || _        d S )NÚserver)ÚsuperÚ__init__Úissuer)Úselfr   r   ÚargsÚkwargsÚ	__class__s        €úŸ/Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/authlib/oauth2/rfc9068/introspection.pyr   z!JWTIntrospectionEndpoint.__init__,   s/   ø€ Ø‰ŒÔ˜$Ð8 vÐ8°Ð8Ð8Ð8ØˆŒˆˆó    c                 ó–   — |                       |¦  «        }|                      ||¦  «        }|                      |¦  «        }d|t          fS )Ú éÈ   )Úauthenticate_endpoint_clientÚauthenticate_tokenÚcreate_introspection_payloadr   )r   ÚrequestÚclientÚtokenÚbodys        r   Úcreate_endpoint_responsez1JWTIntrospectionEndpoint.create_endpoint_response0   sQ   € ð ×2Ò2°7Ñ;Ô;ˆð ×'Ò'¨°Ñ8Ô8ˆð ×0Ò0°Ñ7Ô7ˆØDÕ.Ð.Ð.r   c                 óŠ  — |                       ||¦  «         |j                             d¦  «        dvrt          ¦   «         ‚t	          | j        d¬¦  «        }| j        |_        	 |                     |j        d         ¦  «        }n!# t          $ r}t          ¦   «         |‚d}~ww xY w|r|  	                    |||¦  «        r|S dS dS )r   Útoken_type_hint)Úaccess_tokenNN)r   Úresource_serverr!   )
Úcheck_paramsÚformÚgetr   r   r   Úget_jwksr   r   Úcheck_permission)r   r   r    Ú	validatorr!   Úexcs         r   r   z+JWTIntrospectionEndpoint.authenticate_token=   sî   € à×Ò˜' 6Ñ*Ô*Ð*ð Œ<×ÒÐ-Ñ.Ô.Ð6LÐLÐLÝ#Ñ%Ô%Ð%å+°4´;ÐPTÐUÑUÔUˆ	Ø!œ]ˆ	Ôð	/Ø×0Ò0°´¸gÔ1FÑGÔGˆEˆEøõ !ð 	/ð 	/ð 	/Ý#Ñ%Ô%¨3Ð.øøøøð	/øøøð ð 	T×*Ò*¨5°&¸'ÑBÔBð 	ØˆLð	ð 	ð 	ð 	s   Á$ B Â
B#ÂBÂB#c           
      ó‚  — |sddiS 	 |                      ¦   «          nJ# t          $ r ddicY S t          $ r.}|j        dk    rt	          ¦   «         |‚t          ¦   «         |‚d }~ww xY wdd|d         |d         |d         |d	         |d         |d
         |d         dœ	}|                      |d         ¦  «        x}r||d<   |S )NÚactiveFÚissTÚBearerÚ	client_idÚscopeÚsubÚaudÚexpÚiat)	r0   Ú
token_typer3   r4   r5   r6   r1   r7   r8   Úusername)Úvalidater   r   Ú
claim_namer   r   Úget_username)r   r!   r.   Úpayloadr:   s        r   r   z5JWTIntrospectionEndpoint.create_introspection_payloadQ   s  € Øð 	%Ø˜eÐ$Ð$ð	/ØNŠNÑÔÐÐøÝ ð 	%ð 	%ð 	%Ø˜eÐ$Ð$Ð$Ð$Ý ð 	/ð 	/ð 	/ØŒ~ Ò&Ð&Ý'Ñ)Ô)¨sÐ2Ý#Ñ%Ô%¨3Ð.øøøøð	/øøøð Ø"Ø˜{Ô+Ø˜7”^Ø˜”<Ø˜”<Ø˜”<Ø˜”<Ø˜”<ð

ð 

ˆð ×(Ò(¨¨u¬Ñ6Ô6Ð6ˆ8ð 	+Ø"*ˆGJÑàˆs   ˆ A$­	A$¶)AÁA$c                 ó   — t          ¦   «         ‚)zÕReturn the JWKs that will be used to check the JWT access token signature.
        Developers MUST re-implement this method::

            def get_jwks(self):
                return load_jwks("jwks.json")
        )ÚNotImplementedError)r   s    r   r+   z!JWTIntrospectionEndpoint.get_jwkso   s   € õ "Ñ#Ô#Ð#r   Úuser_idÚreturnc                 ó   — dS )zÁReturns an username from a user ID.
        Developers MAY re-implement this method::

            def get_username(self, user_id):
                return User.get(id=user_id).username
        N© )r   rA   s     r   r=   z%JWTIntrospectionEndpoint.get_usernamex   s	   € ð ˆtr   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚENDPOINT_NAMEr   r#   r   r   r+   Ústrr=   Ú__classcell__)r   s   @r   r   r      s¬   ø€ € € € € ðð ð< $€Mðð ð ð ð ð ð/ð /ð /ðð ð ð(ð ð ð<$ð $ð $ð Cð ¨Cð ð ð ð ð ð ð ð r   r   N)Úauthlib.common.errorsr   Úauthlib.constsr   Úauthlib.jose.errorsr   r   Úauthlib.oauth2.rfc6750.errorsr   Ú&authlib.oauth2.rfc9068.token_validatorr   Úrfc7662r
   r   rD   r   r   ú<module>rR      sÂ   ðØ 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø /Ð /Ð /Ð /Ð /Ð /Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø JÐ JÐ JÐ JÐ JÐ Jà +Ð +Ð +Ð +Ð +Ð +ðtð tð tð tð tÐ4ñ tô tð tð tð tr   