Ë
    †Kài*  ã                   ó´   — 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
 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«      Zy)é    )ÚJsonWebSignature)ÚJsonWebToken)Ú	JoseErroré   )ÚAuthorizationServer)ÚClientMixin)ÚInvalidRequestError)Ú_validate_client)ÚBasicOAuth2Payload)ÚOAuth2Requesté   )ÚInvalidRequestObjectError)ÚInvalidRequestUriError)ÚRequestNotSupportedError)ÚRequestUriNotSupportedErrorc                   ó®   — e Zd ZdZddedefd„Zdefd„Zdedefd„Z	deded	e
d
efd„Zdeded
efd„Zd	e
defd„Zdefd„Zd	e
fd„Zd
efd„Zd	e
d
efd„Zy)ÚJWTAuthenticationRequesta  Authorization server extension implementing the support
    for JWT secured authentication request, as defined in :rfc:`RFC9101 <9101>`.

    :param support_request: Whether to enable support for the ``request`` parameter.
    :param support_request_uri: Whether to enable support for the ``request_uri`` parameter.

    This extension is intended to be inherited and registered into the authorization server::

        class JWTAuthenticationRequest(rfc9101.JWTAuthenticationRequest):
            def resolve_client_public_key(self, client: ClientMixin):
                return get_jwks_for_client(client)

            def get_request_object(self, request_uri: str):
                try:
                    return requests.get(request_uri).text
                except requests.Exception:
                    return None

            def get_server_metadata(self):
                return {
                    "issuer": ...,
                    "authorization_endpoint": ...,
                    "require_signed_request_object": ...,
                }

            def get_client_require_signed_request_object(self, client: ClientMixin):
                return client.require_signed_request_object


        authorization_server.register_extension(JWTAuthenticationRequest())
    Úsupport_requestÚsupport_request_uric                 ó    — || _         || _        y ©N)r   r   )Úselfr   r   s      úw/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/authlib/oauth2/rfc9101/authorization_server.pyÚ__init__z!JWTAuthenticationRequest.__init__2   s   € Ø.ˆÔØ#6ˆÕ ó    Úauthorization_serverc                 ó<   — |j                  d| j                  «       y )NÚbefore_get_authorization_grant)Úregister_hookÚparse_authorization_request)r   r   s     r   Ú__call__z!JWTAuthenticationRequest.__call__6   s   € Ø×*Ñ*Ø,¨d×.NÑ.Nõ	
r   Úrequestc                 óî   — t        |j                  |j                  j                  «      }| j	                  |||«      sy | j                  ||«      }| j                  |||«      }t        |«      }||_        y r   )r
   Úquery_clientÚpayloadÚ	client_idÚ"_shoud_proceed_with_request_objectÚ_get_raw_request_objectÚ_decode_request_objectr   )r   r   r"   ÚclientÚraw_request_objectÚrequest_objectr%   s          r   r    z4JWTAuthenticationRequest.parse_authorization_request;   s   € ô "Ø ×-Ñ-¨w¯©×/HÑ/Hó
ˆð ×6Ñ6Ø  '¨6ô
ð à!×9Ñ9Ð:NÐPWÓXÐØ×4Ñ4ØVÐ/ó
ˆô % ^Ó4ˆØ!ˆr   r*   Úreturnc                 ó¨  — d|j                   j                  v r9d|j                   j                  v r!t        d|j                   j                  ¬«      ‚d|j                   j                  v r-| j                  s t        |j                   j                  ¬«      ‚yd|j                   j                  v r-| j                  s t        |j                   j                  ¬«      ‚y| j                  |«      r!t        d|j                   j                  ¬«      ‚| j                  «       }|r3|j                  dd«      r!t        d	|j                   j                  ¬«      ‚y)
Nr"   Úrequest_urizBThe 'request' and 'request_uri' parameters are mutually exclusive.©ÚstateTúGAuthorization requests for this client must use signed request objects.Úrequire_signed_request_objectFúGAuthorization requests for this server must use signed request objects.)r%   Údatar	   r1   r   r   r   r   Ú(get_client_require_signed_request_objectÚget_server_metadataÚget)r   r   r"   r*   Úmetadatas        r   r'   z;JWTAuthenticationRequest._shoud_proceed_with_request_objectM   s  € ð ˜Ÿ™×,Ñ,Ñ,°À'Ç/Á/×BVÑBVÑ1VÜ%ØTØ—o‘o×+Ñ+ôð ð
 ˜Ÿ™×,Ñ,Ñ,Ø×'Ò'Ü.°W·_±_×5JÑ5JÔKÐKØà˜GŸO™O×0Ñ0Ñ0Ø×+Ò+Ü1¸¿¹×8MÑ8MÔNÐNØð
 ×8Ñ8¸Ô@Ü%ØYØ—o‘o×+Ñ+ôð ð ×+Ñ+Ó-ˆÙ˜Ÿ™Ð%DÀeÔLÜ%ØYØ—o‘o×+Ñ+ôð ð
 r   c                 ó   — d|j                   j                  v rL| j                  |j                   j                  d   «      }|s t        |j                   j                  ¬«      ‚|S |j                   j                  d   }|S )Nr/   r0   r"   )r%   r5   Úget_request_objectr   r1   )r   r   r"   r+   s       r   r(   z0JWTAuthenticationRequest._get_raw_request_objectx   sx   € ð ˜GŸO™O×0Ñ0Ñ0Ø!%×!8Ñ!8Ø—‘×$Ñ$ ]Ñ3ó"Ðñ &Ü,°7·?±?×3HÑ3HÔIÐIð
 "Ð!ð ")§¡×!5Ñ!5°iÑ!@Ðà!Ð!r   r+   c                 ón  — | j                  |«      }	 t        t        t        j                  j                  «       «      «      }|j                  ||«      }|j                  «        | j                  |«      r3|j                  d   dk(  r!t        d|j                  j                  ¬«      ‚| j!                  «       }|rE|j#                  dd«      r3|j                  d   dk(  r!t        d|j                  j                  ¬«      ‚|d	   |j                  j$                  k7  r!t        d
|j                  j                  ¬«      ‚d|v sd|v r!t        d|j                  j                  ¬«      ‚|S # t        $ rC}t        |j                  xs t        j                  |j                  j                  ¬«      |‚d }~ww xY w)N)Údescriptionr1   ÚalgÚnoner2   r0   r3   Fr4   r&   z\The 'client_id' claim from the request parameters and the request object claims don't match.r"   r/   zVThe 'request' and 'request_uri' parameters must not be included in the request object.)Úresolve_client_public_keyr   Úlistr   ÚALGORITHMS_REGISTRYÚkeysÚdecodeÚvalidater   r   r=   r%   r1   r6   Úheaderr	   r7   r8   r&   )	r   r"   r*   r+   ÚjwksÚjwtr,   Úerrorr9   s	            r   r)   z/JWTAuthenticationRequest._decode_request_object‡   sœ  € ð ×-Ñ-¨fÓ5ˆð		ÜœtÔ$4×$HÑ$H×$MÑ$MÓ$OÓPÓQˆCØ ŸZ™ZÐ(:¸DÓAˆNØ×#Ñ#Ô%ð ×9Ñ9¸&ÔAØ×%Ñ% eÑ,°Ò6ä%ØYØ—o‘o×+Ñ+ôð ð ×+Ñ+Ó-ˆáØ—‘Ð<¸eÔDØ×%Ñ% eÑ,°Ò6ä%ØYØ—o‘o×+Ñ+ôð ð ˜+Ñ&¨'¯/©/×*CÑ*CÒCÜ%ð=à—o‘o×+Ñ+ôð ð ˜Ñ&¨-¸>Ñ*IÜ%ØhØ—o‘o×+Ñ+ôð ð
 Ðøôc ò 	Ü+Ø!×-Ñ-ÒVÔ1J×1VÑ1VØ—o‘o×+Ñ+ôð ðûð	ús   “AE( Å(	F4Å1>F/Æ/F4r/   c                 ó   — t        «       ‚)aÊ  Download the request object at ``request_uri``.

        This method must be implemented if the ``request_uri`` parameter is supported::

            class JWTAuthenticationRequest(rfc9101.JWTAuthenticationRequest):
                def get_request_object(self, request_uri: str):
                    try:
                        return requests.get(request_uri).text
                    except requests.Exception:
                        return None
        ©ÚNotImplementedError)r   r/   s     r   r;   z+JWTAuthenticationRequest.get_request_objectÃ   ó   € ô "Ó#Ð#r   c                 ó   — t        «       ‚)a   Resolve the client public key for verifying the JWT signature.
        A client may have many public keys, in this case, we can retrieve it
        via ``kid`` value in headers. Developers MUST implement this method::

            class JWTAuthenticationRequest(rfc9101.JWTAuthenticationRequest):
                def resolve_client_public_key(self, client):
                    if client.jwks_uri:
                        return requests.get(client.jwks_uri).json

                    return client.jwks
        rK   ©r   r*   s     r   Úresolve_client_public_keysz3JWTAuthenticationRequest.resolve_client_public_keysÑ   rM   r   c                 ó   — i S )aÐ  Return server metadata which includes supported grant types,
        response types and etc.

        When the ``require_signed_request_object`` claim is :data:`True`,
        all clients require that authorization requests
        use request objects, and an error will be returned when the authorization
        request payload is passed in the request body or query string::

            class JWTAuthenticationRequest(rfc9101.JWTAuthenticationRequest):
                def get_server_metadata(self):
                    return {
                        "issuer": ...,
                        "authorization_endpoint": ...,
                        "require_signed_request_object": ...,
                    }

        © )r   s    r   r7   z,JWTAuthenticationRequest.get_server_metadataß   s	   € ð$ ˆ	r   c                  ó   — y)aI  Return the 'require_signed_request_object' client metadata.

        When :data:`True`, the client requires that authorization requests
        use request objects, and an error will be returned when the authorization
        request payload is passed in the request body or query string::

           class JWTAuthenticationRequest(rfc9101.JWTAuthenticationRequest):
               def get_client_require_signed_request_object(self, client):
                   return client.require_signed_request_object

        If not implemented, the value is considered as :data:`False`.
        FrR   rO   s     r   r6   zAJWTAuthenticationRequest.get_client_require_signed_request_objectó   s   € ð r   N)TT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úboolr   r   r!   r   r    r   r'   Ústrr(   r)   r;   rP   Údictr7   r6   rR   r   r   r   r      sÓ   „ ññ@7¨ð 7È$ó 7ð
Ð-@ó 
ð
"Ø$7ð"ØBOó"ð$)à1ð)ð ð)ð ð	)ð
 
ó)ðV"Ø$7ð"ØBOð"à	ó"ð:Ø*ð:Ø@Có:ðx$¨có $ð$°ó $ð Tó ð(¸{ð Ètô r   r   N)Úauthlib.joser   r   Úauthlib.jose.errorsr   Úrfc6749r   r   r	   Úrfc6749.authenticate_clientr
   Úrfc6749.requestsr   r   Úerrorsr   r   r   r   r   rR   r   r   ú<module>ra      s8   ðÝ )Ý %Ý )å )Ý !Ý )Ý :Ý 1Ý ,Ý -Ý *Ý ,Ý /÷oò or   