§
    (ê[f5  ã                   óŠ   — d dl Z d dlZd dlmZmZmZ ddlmZmZm	Z	  e j
        d¦  «        Zd„ Zd„ Zd„ Z G d	„ d
¦  «        ZdS )é    N)Úto_bytesÚ
to_unicodeÚurlsafe_b64encodeé   )ÚInvalidRequestErrorÚInvalidGrantErrorÚOAuth2Requestz^[a-zA-Z0-9\-._~]{43,128}$c                 ó¢   — t          j        t          | d¦  «        ¦  «                             ¦   «         }t	          t          |¦  «        ¦  «        S )z8Create S256 code_challenge with the given code_verifier.Úascii)ÚhashlibÚsha256r   Údigestr   r   )Úcode_verifierÚdatas     úT/var/www/piapp/venv/lib/python3.11/site-packages/authlib/oauth2/rfc7636/challenge.pyÚcreate_s256_code_challenger      s>   € åŒ>�( =°'Ñ:Ô:Ñ;Ô;×BÒBÑDÔD€DÝÕ'¨Ñ-Ô-Ñ.Ô.Ð.ó    c                 ó   — | |k    S ©N© ©r   Úcode_challenges     r   Úcompare_plain_code_challenger      s   € ð ˜NÒ*Ð*r   c                 ó(   — t          | ¦  «        |k    S r   )r   r   s     r   Úcompare_s256_code_challenger      s   € å% mÑ4Ô4¸ÒFÐFr   c                   óN   — e Zd ZdZdZddgZeedœZdd„Z	d„ Z
d„ Zd	„ Zd
„ Zd„ ZdS )ÚCodeChallengea  CodeChallenge extension to Authorization Code Grant. It is used to
    improve the security of Authorization Code flow for public clients by
    sending extra "code_challenge" and "code_verifier" to the authorization
    server.

    The AuthorizationCodeGrant SHOULD save the ``code_challenge`` and
    ``code_challenge_method`` into database when ``save_authorization_code``.
    Then register this extension via::

        server.register_grant(
            AuthorizationCodeGrant,
            [CodeChallenge(required=True)]
        )
    ÚplainÚS256)r   r   Tc                 ó   — || _         d S r   )Úrequired)Úselfr!   s     r   Ú__init__zCodeChallenge.__init__8   s   € Ø ˆŒˆˆr   c                 ór   — |                      d| j        ¦  «         |                      d| j        ¦  «         d S )NÚ$after_validate_authorization_requestÚafter_validate_token_request)Úregister_hookÚvalidate_code_challengeÚvalidate_code_verifier)r"   Úgrants     r   Ú__call__zCodeChallenge.__call__;   sP   € Ø×ÒØ2ØÔ(ñ	
ô 	
ð 	
ð 	×ÒØ*ØÔ'ñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óâ   — |j         }|j                             d¦  «        }|j                             d¦  «        }|s|sd S |st          d¦  «        ‚|r|| j        vrt          d¦  «        ‚d S d S )Nr   Úcode_challenge_methodzMissing "code_challenge"z#Unsupported "code_challenge_method")Úrequestr   Úgetr   ÚSUPPORTED_CODE_CHALLENGE_METHOD)r"   r*   r.   Ú	challengeÚmethods        r   r(   z%CodeChallenge.validate_code_challengeE   s˜   € Ø!&¤ˆØ”L×$Ò$Ð%5Ñ6Ô6ˆ	Ø”×!Ò!Ð"9Ñ:Ô:ˆØð 	 ð 	ØˆFàð 	BÝ%Ð&@ÑAÔAÐAàð 	M�f DÔ$HÐHÐHÝ%Ð&KÑLÔLÐLð	Mð 	MÐHÐHr   c                 ó  — |j         }|j                             d¦  «        }| j        r|j        dk    r|st          d¦  «        ‚|j        }|                      |¦  «        }|s|sd S |st          d¦  «        ‚t           	                    |¦  «        st          d¦  «        ‚|  
                    |¦  «        }|€| j        }| j                             |¦  «        }|st          d|› d�¦  «        ‚ |||¦  «        st          d¬¦  «        ‚d S )	Nr   ÚnonezMissing "code_verifier"zInvalid "code_verifier"zNo verify method for "ú"zCode challenge failed.)Údescription)r.   Úformr/   r!   Úauth_methodr   Úauthorization_codeÚ get_authorization_code_challengeÚCODE_VERIFIER_PATTERNÚmatchÚ'get_authorization_code_challenge_methodÚDEFAULT_CODE_CHALLENGE_METHODÚCODE_CHALLENGE_METHODSÚRuntimeErrorr   )r"   r*   r.   Úverifierr9   r1   r2   Úfuncs           r   r)   z$CodeChallenge.validate_code_verifierR   sP  € Ø!&¤ˆØ”<×#Ò# OÑ4Ô4ˆð Œ=ð 	A˜WÔ0°FÒ:Ð:À8Ð:Ý%Ð&?Ñ@Ô@Ð@à$Ô7ÐØ×9Ò9Ð:LÑMÔMˆ	ð ð 	 ð 	ØˆFð ð 	AÝ%Ð&?Ñ@Ô@Ð@å$×*Ò*¨8Ñ4Ô4ð 	AÝ%Ð&?Ñ@Ô@Ð@ð ×=Ò=Ð>PÑQÔQˆØˆ>ØÔ7ˆFàÔ*×.Ò.¨vÑ6Ô6ˆØð 	CÝÐA¸ÐAÐAÐAÑBÔBÐBð ˆt�H˜iÑ(Ô(ð 	JÝ#Ð0HÐIÑIÔIÐIð	Jð 	Jr   c                 ó   — |j         S )a[  Get "code_challenge" associated with this authorization code.
        Developers MAY re-implement it in subclass, the default logic::

            def get_authorization_code_challenge(self, authorization_code):
                return authorization_code.code_challenge

        :param authorization_code: the instance of authorization_code
        )r   ©r"   r9   s     r   r:   z.CodeChallenge.get_authorization_code_challengev   s   € ð "Ô0Ð0r   c                 ó   — |j         S )ap  Get "code_challenge_method" associated with this authorization code.
        Developers MAY re-implement it in subclass, the default logic::

            def get_authorization_code_challenge_method(self, authorization_code):
                return authorization_code.code_challenge_method

        :param authorization_code: the instance of authorization_code
        )r-   rD   s     r   r=   z5CodeChallenge.get_authorization_code_challenge_method�   s   € ð "Ô7Ð7r   N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r>   r0   r   r   r?   r#   r+   r(   r)   r:   r=   r   r   r   r   r      s¬   € € € € € ðð ð %,Ð!à'.°Ð&7Ð#ð .Ø+ðð Ðð
!ð !ð !ð !ð
ð 
ð 
ðMð Mð Mð"Jð "Jð "JðH	1ð 	1ð 	1ð	8ð 	8ð 	8ð 	8ð 	8r   r   )Úrer   Úauthlib.common.encodingr   r   r   Úrfc6749r   r   r	   Úcompiler;   r   r   r   r   r   r   r   ú<module>rN      sè   ðØ 	€	€	€	Ø €€€Ø KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ Kðð ð ð ð ð ð ð ð ð ð #˜œ
Ð#@ÑAÔAÐ ð/ð /ð /ð+ð +ð +ðGð Gð Gð
k8ð k8ð k8ð k8ð k8ñ k8ô k8ð k8ð k8ð k8r   