+
    P(i                         ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHt ^RIHt ^RIHt ^RIH	t	 ]P                  ! R4      t]P                  ! R4      tR	 tR
 tR t ! R R4      tR# )    N)to_bytes)
to_unicode)urlsafe_b64encode)InvalidGrantError)InvalidRequestError)OAuth2Requestz^[a-zA-Z0-9\-._~]{43,128}$c                    \         P                  ! \        V R4      4      P                  4       p\	        \        V4      4      # )z8Create S256 code_challenge with the given code_verifier.ascii)hashlibsha256r   digestr   r   )code_verifierdatas   & f/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/authlib/oauth2/rfc7636/challenge.pycreate_s256_code_challenger      s1    >>(=':;BBDD'-..    c                 
    W8H  # N r   code_challenges   &&r   compare_plain_code_challenger      s     **r   c                     \        V 4      V8H  # r   )r   r   s   &&r   compare_s256_code_challenger      s    %m4FFr   c                   d   a  ] tR t^!t o RtRtRR.tR]R]/t	RR lt
R tR tR tR tR	 tR
tV tR# )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S256c                    Wn         R # r   required)selfr!   s   &&r   __init__CodeChallenge.__init__8   s     r   c                v    VP                  R V P                  4       VP                  RV P                  4       R# ),after_validate_authorization_request_payloadafter_validate_token_requestN)register_hookvalidate_code_challengevalidate_code_verifier)r"   grants   &&r   __call__CodeChallenge.__call__;   s8    :((	
 	*''	
r   c                   VP                   pVP                  P                  P                  R 4      pVP                  P                  P                  R4      pV'       g   V'       g   R# V'       g   \	        R4      h\        VP                  P                  P                  R . 4      4      ^8  d   \	        R4      h\        P                  V4      '       g   \	        R4      hV'       d   WPP                  9  d   \	        R4      h\        VP                  P                  P                  R. 4      4      ^8  d   \	        R4      hR# )r   code_challenge_methodNzMissing 'code_challenge'z%Multiple 'code_challenge' in request.zInvalid 'code_challenge'z#Unsupported 'code_challenge_method'z,Multiple 'code_challenge_method' in request.)
requestpayloadr   getr   lendatalistCODE_CHALLENGE_PATTERNmatchSUPPORTED_CODE_CHALLENGE_METHOD)r"   r+   redirect_urir0   	challengemethods   &&&   r   r)   %CodeChallenge.validate_code_challengeE   s    !&OO((,,-=>	%%))*AB%&@AAw''++,<bABQF%&MNN%++I66%&@AAf$H$HH%&KLLw''++,CRHIAM%&TUU Nr   c                j   VP                   pVP                  P                  R 4      pV P                  '       d%   VP                  R8X  d   V'       g   \        R4      hVP                  pV P                  V4      pV'       g   V'       g   R# V'       g   \        R4      h\        P                  V4      '       g   \        R4      hV P                  V4      pVf   V P                  pV P                  P                  V4      pV'       g   \        RV R24      hV! WF4      '       g   \        RR7      hR# )	r   nonezMissing 'code_verifier'NzInvalid 'code_verifier'zNo verify method for ''zCode challenge failed.)description)r0   formr2   r!   auth_methodr   authorization_code get_authorization_code_challengeCODE_VERIFIER_PATTERNr6   'get_authorization_code_challenge_methodDEFAULT_CODE_CHALLENGE_METHODCODE_CHALLENGE_METHODSRuntimeErrorr   )	r"   r+   resultr0   verifierrB   r9   r:   funcs	   &&&      r   r*   $CodeChallenge.validate_code_verifier[   s	   !&<<##O4 ===W00F:8%&?@@$7799:LM	  %&?@@$**844%&?@@ ==>PQ>77F**..v6!7xqABB H((#0HII )r   c                    VP                   # )a3  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"   rB   s   &&r   rC   .CodeChallenge.get_authorization_code_challenge   s     "000r   c                    VP                   # )aH  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/   rN   s   &&r   rE   5CodeChallenge.get_authorization_code_challenge_method   s     "777r   r    N)T)__name__
__module____qualname____firstlineno____doc__rF   r7   r   r   rG   r#   r,   r)   r*   rC   rE   __static_attributes____classdictcell__)__classdict__s   @r   r   r   !   sY     
 %,!'.&7# 	-+
!
V,"JH	1	8 	8r   r   )r   reauthlib.common.encodingr   r   r   rfc6749r   r   r   compilerD   r5   r   r   r   r   r   r   r   <module>r^      sY     	 , . 5 ' ) #

#@A $AB /+G
r8 r8r   