ó
    æk7i€)  ã                   ó¨   • S SK Jr  S SKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  S
SKJr  S
SKJr  S
SKJr  S
SKJr   " S S5      rg)é    )Újwt)Ú	JoseErroré   )ÚAuthorizationServer)ÚClientMixin)ÚInvalidRequestError)Ú_validate_client)ÚBasicOAuth2Payload)ÚOAuth2Requesté   )ÚInvalidRequestObjectError)ÚInvalidRequestUriError)ÚRequestNotSupportedError)ÚRequestUriNotSupportedErrorc                   óÌ   • \ rS rSrSrSS\S\4S jjrS\4S jrS\S\	4S	 jr
S\S\	S
\S\4S jrS\S\	S\4S jrS
\S\4S jrS\4S jrS
\4S jrS\4S jrS
\S\4S jrSrg)ÚJWTAuthenticationRequesté   a©  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                 ó   • Xl         X l        g ©N©r   r   )Úselfr   r   s      Úe/home/james-whalen/.local/lib/python3.13/site-packages/authlib/oauth2/rfc9101/authorization_server.pyÚ__init__Ú!JWTAuthenticationRequest.__init__1   s   € Ø.ÔØ#6Õ ó    Úauthorization_serverc                 ó<   • UR                  SU R                  5        g )NÚbefore_get_authorization_grant)Úregister_hookÚparse_authorization_request)r   r   s     r   Ú__call__Ú!JWTAuthenticationRequest.__call__5   s   € Ø×*Ñ*Ø,¨d×.NÑ.Nõ	
r   Úrequestc                 óð   • [        UR                  UR                  R                  5      nU R	                  XU5      (       d  g U R                  X5      nU R                  X#U5      n[        U5      nXbl        g 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"   Ú4JWTAuthenticationRequest.parse_authorization_request:   s{   € ô "Ø ×-Ñ-¨w¯©×/HÑ/Hó
ˆð ×6Ñ6Ø ¨6÷
ñ 
ð à!×9Ñ9Ð:NÓXÐØ×4Ñ4ØÐ/ó
ˆô % ^Ó4ˆØ!r   r-   Úreturnc                 óÌ  • SUR                   R                  ;   a8  SUR                   R                  ;   a  [        SUR                   R                  S9eSUR                   R                  ;   a/  U R                  (       d  [        UR                   R                  S9egSUR                   R                  ;   a/  U R                  (       d  [        UR                   R                  S9egU R                  U5      (       a  [        SUR                   R                  S9eU R                  5       nU(       a5  UR                  SS5      (       a  [        S	UR                   R                  S9eg)
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   r5   r   r   r   r   Ú(get_client_require_signed_request_objectÚget_server_metadataÚget)r   r   r%   r-   Úmetadatas        r   r*   Ú;JWTAuthenticationRequest._shoud_proceed_with_request_objectL   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ÑLÜ%ØYØ—o‘o×+Ñ+ñð ð
 r   c                 ó
  • SUR                   R                  ;   aO  U R                  UR                   R                  S   5      nU(       d  [        UR                   R                  S9e U$ UR                   R                  S   nU$ )Nr3   r4   r%   )r(   r9   Úget_request_objectr   r5   )r   r   r%   r.   s       r   r+   Ú0JWTAuthenticationRequest._get_raw_request_objectw   s}   € ð ˜GŸO™O×0Ñ0Ó0Ø!%×!8Ñ!8Ø—‘×$Ñ$ ]Ñ3ó"Ðö &Ü,°7·?±?×3HÑ3HÑIÐIð &ð "Ð!ð ")§¡×!5Ñ!5°iÑ!@Ðà!Ð!r   r.   c                 ó0  • U R                  U5      n [        R                  " X45      nUR                  5         U R                  U5      (       a1  UR                  S   S:X  a  [        SUR                  R                  S9eU R                  5       nU(       aH  UR                  SS5      (       a1  UR                  S   S:X  a  [        SUR                  R                  S9eUS	   UR                  R                  :w  a  [        S
UR                  R                  S9eSU;   d  SU;   a  [        SUR                  R                  S9eU$ ! [         aE  n[        UR                  =(       d    [
        R                  UR                  R                  S9UeS nAff = f)N)Údescriptionr5   ÚalgÚnoner6   r4   r7   Fr8   r)   z\The 'client_id' claim from the request parameters and the request object claims don't match.r%   r3   zVThe 'request' and 'request_uri' parameters must not be included in the request object.)Úresolve_client_public_keyr   ÚdecodeÚvalidater   r   rC   r(   r5   r:   Úheaderr   r;   r<   r)   )r   r%   r-   r.   Újwksr/   Úerrorr=   s           r   r,   Ú/JWTAuthenticationRequest._decode_request_object†   s  € ð ×-Ñ-¨fÓ5ˆð	Ü ŸZšZÐ(:ÓAˆNØ×#Ñ#Ô%ð ×9Ñ9¸&×AÑAØ×%Ñ% eÑ,°Ó6ä%ØYØ—o‘o×+Ñ+ñð ð ×+Ñ+Ó-ˆæØ—‘Ð<¸e×DÑDØ×%Ñ% eÑ,°Ó6ä%ØYØ—o‘o×+Ñ+ñð ð ˜+Ñ&¨'¯/©/×*CÑ*CÓCÜ%ð=à—o‘o×+Ñ+ñð ð ˜Ó&¨-¸>Ó*IÜ%ØhØ—o‘o×+Ñ+ñð ð
 Ðøôc ó 	Ü+Ø!×-Ñ-×VÔ1J×1VÑ1VØ—o‘o×+Ñ+ñð ðûð	ús   “&E Å
FÅA FÆFr3   c                 ó   • [        5       e)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   r3   s     r   r@   Ú+JWTAuthenticationRequest.get_request_objectÂ   ó   € ô "Ó#Ð#r   c                 ó   • [        5       e)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
rN   ©r   r-   s     r   Úresolve_client_public_keysÚ3JWTAuthenticationRequest.resolve_client_public_keysÐ   rQ   r   c                 ó   • 0 $ )ah  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   r;   Ú,JWTAuthenticationRequest.get_server_metadataÞ   s	   € ð$ ˆ	r   c                 ó   • g)a	  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`.
FrW   rS   s     r   r:   ÚAJWTAuthenticationRequest.get_client_require_signed_request_objectò   s   € ð r   r   N)TT)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úboolr   r   r#   r   r"   r   r*   Ústrr+   r,   r@   rT   Údictr;   r:   Ú__static_attributes__rW   r   r   r   r      sÓ   † ññ@7¨ð 7È$õ 7ð
Ð-@ô 
ð
"Ø$7ð"ØBOô"ð$)à1ð)ð ð)ð ð	)ð
 
ô)ðV"Ø$7ð"ØBOð"à	ô"ð:Ø*ð:Ø@Cô:ðx$¨cô $ð$°ô $ð Tô ð(¸{ð Èt÷ r   r   N)Úauthlib.joser   Úauthlib.jose.errorsr   Úrfc6749r   r   r   Úrfc6749.authenticate_clientr	   Úrfc6749.requestsr
   r   Úerrorsr   r   r   r   r   rW   r   r   Ú<module>rj      s5   ðÝ Ý )å )Ý !Ý )Ý :Ý 1Ý ,Ý -Ý *Ý ,Ý /÷oò or   