
    qh|]                         S SK r S SKJrJr  S SKJrJr  S SKJr  S SKJrJ	r	  S SK
r
\ R                  " \5      r " S S\5      r " S S	\
R                   5      rg)
    N)generate_token	urldecode)WebApplicationClientInsecureTransportError)LegacyApplicationClient)TokenExpiredErroris_secure_transportc                   (   ^  \ rS rSrU 4S jrSrU =r$ )TokenUpdated   c                 6   > [         [        U ]  5         Xl        g N)superr   __init__token)selfr   	__class__s     R/var/www/html/env/lib/python3.13/site-packages/requests_oauthlib/oauth2_session.pyr   TokenUpdated.__init__   s    lD*,
    r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__r   s   @r   r   r      s     r   r   c                     ^  \ rS rSrSr          SU 4S jjr\S 5       r\R                  S 5       rS r	\S 5       r
\
R                  S 5       r
\
R                  S	 5       r
\S
 5       r\R                  S 5       r\S 5       r\R                  S 5       r\R                  S 5       r\S 5       rSS jr               SS jrS r       SS jr      SU 4S jjrS rSrU =r$ )OAuth2Session   a  Versatile OAuth 2 extension to :class:`requests.Session`.

Supports any grant type adhering to :class:`oauthlib.oauth2.Client` spec
including the four core OAuth 2 grants.

Can be used to create authorization urls, fetch tokens and access protected
resources using the :class:`requests.Session` interface you are used to.

- :class:`oauthlib.oauth2.WebApplicationClient` (default): Authorization Code Grant
- :class:`oauthlib.oauth2.MobileApplicationClient`: Implicit Grant
- :class:`oauthlib.oauth2.LegacyApplicationClient`: Password Credentials Grant
- :class:`oauthlib.oauth2.BackendApplicationClient`: Client Credentials Grant

Note that the only time you will be using Implicit Grant from python is if
you are driving a user agent able to obtain URL fragments.
c                   > [         [        U ]
  " S0 UD6  U=(       d	    [        XS9U l        U=(       d    0 U l        XPl        X`l        U=(       d    [        U l	        Xl
        X0l        U=(       d    0 U l        Xl        Xl        U R                  S;  a/  [        SR!                  U R"                  U R                  5      5      eS U l        ['        5       ['        5       ['        5       ['        5       ['        5       S.U l        g)a  Construct a new OAuth 2 client session.

:param client_id: Client id obtained during registration
:param client: :class:`oauthlib.oauth2.Client` to be used. Default is
               WebApplicationClient which is useful for any
               hosted application but not mobile or desktop.
:param scope: List of scopes you wish to request access to
:param redirect_uri: Redirect URI you registered as callback
:param token: Token dictionary, must include access_token
              and token_type.
:param state: State string used to prevent CSRF. This will be given
              when creating the authorization url and must be supplied
              when parsing the authorization response.
              Can be either a string or a no argument callable.
:auto_refresh_url: Refresh token endpoint URL, must be HTTPS. Supply
                   this if you wish the client to automatically refresh
                   your access tokens.
:auto_refresh_kwargs: Extra arguments to pass to the refresh token
                      endpoint.
:token_updater: Method with one argument, token, to be used to update
                your token database on automatic token refresh. If not
                set a TokenUpdated warning will be raised when a token
                has been refreshed. This warning will carry the token
                in its token argument.
:param pkce: Set "S256" or "plain" to enable PKCE. Default is disabled.
:param kwargs: Arguments to pass to the Session constructor.
r   )S256plainNzWrong value for {}(.., pkce={})c                     U $ r    )rs    r   <lambda>(OAuth2Session.__init__.<locals>.<lambda>^   s    ar   )access_token_responserefresh_token_responseprotected_requestrefresh_token_requestaccess_token_requestNr&   )r   r    r   r   _clientr   _scoperedirect_urir   state_stateauto_refresh_urlauto_refresh_kwargstoken_updater_pkceAttributeErrorformatr   authsetcompliance_hook)r   	client_idclientr4   r5   scoper1   r   r2   r6   pkcekwargsr   s               r   r   OAuth2Session.__init__$   s    R 	mT+5f5M!5i!M[b
(,n
 0#6#<" *
::44 !B!I!I$..Z^ZdZd!eff  	
 &)U&)e!$%(U$'E 
r   c                 |    U R                   b  U R                   $ U R                  b  U R                  R                  $ g)zBBy default the scope from the client is used, except if overriddenN)r0   r/   r?   r   s    r   r?   OAuth2Session.scopej   s5     ;;";;\\%<<%%%r   c                     Xl         g r   )r0   )r   r?   s     r   r?   rE   t   s    r   c                     U R                  5       U l        [        R                  SU R                  5        U R                  $ ! [         a?    U R                   U l        [        R                  SU R                  5         U R                  $ f = f)z6Generates a state string to be used in authorizations.zGenerated new state %s.z&Re-using previously supplied state %s.)r2   r3   logdebug	TypeErrorrD   s    r   	new_stateOAuth2Session.new_statex   so    	M**,DKII/= {{  	M**DKII>L{{	Ms   5A ;BBc                 0    [        U R                  SS 5      $ )Nr=   getattrr/   rD   s    r   r=   OAuth2Session.client_id   s    t||[$77r   c                 $    XR                   l        g r   r/   r=   r   values     r   r=   rP      s    !&r   c                     U R                   ?g r   rR   rD   s    r   r=   rP      s    LL"r   c                 0    [        U R                  SS 5      $ )Nr   rN   rD   s    r   r   OAuth2Session.token   s    t||Wd33r   c                 Z    XR                   l        U R                   R                  U5        g r   )r/   r   populate_token_attributesrS   s     r   r   rW      s    "..u5r   c                 0    [        U R                  SS 5      $ )Naccess_tokenrN   rD   s    r   r[   OAuth2Session.access_token   s    t||^T::r   c                 $    XR                   l        g r   r/   r[   rS   s     r   r[   r\      s    $)!r   c                     U R                   ?g r   r^   rD   s    r   r[   r\      s    LL%r   c                 ,    [        U R                  5      $ )aP  Boolean that indicates whether this session has an OAuth token
or not. If `self.authorized` is True, you can reasonably expect
OAuth-protected requests to the resource to succeed. If
`self.authorized` is False, you need the user to go through the OAuth
authentication dance before OAuth-protected requests to the resource
will succeed.
)boolr[   rD   s    r   
authorizedOAuth2Session.authorized   s     D%%&&r   c                    U=(       d    U R                  5       nU R                  (       a`  U R                  R                  S5      U l        U R                  US'   U R                  R                  U R                  U R                  S9US'   U R                  R                  " U4U R                  U R                  US.UD6U4$ )a  Form an authorization URL.

:param url: Authorization endpoint url, must be HTTPS.
:param state: An optional state string for CSRF protection. If not
              given it will be generated for you.
:param kwargs: Extra parameters to include.
:return: authorization_url, state
+   code_challenge_method)code_verifierrf   code_challenge)r1   r?   r2   )	rK   r7   r/   create_code_verifier_code_verifiercreate_code_challengeprepare_request_urir1   r?   )r   urlr2   rA   s       r   authorization_urlOAuth2Session.authorization_url   s     ))::"&,,"C"CB"GD.2jjF*+'+||'I'I"11&*jj (J (F#$
 LL,,!..jj	
  	
 		
r   c                    [        U5      (       d
  [        5       eU(       dA  U(       a:  U R                  R                  X0R                  S9  U R                  R
                  nONU(       dG  [        U R                  [        5      (       a(  U R                  R
                  nU(       d  [        S5      eU R                  (       a'  U R                  c  [        S5      eU R                  US'   [        U R                  [        5      (       a  Uc  [        S5      eUc  [        S5      eUb  UUS'   Ub  UUS'   Ub  Uc  S	nOUUS
LaP  U R                  nU(       a=  [        R                  SU5        Ub  UOSn[        R                   R#                  UU5      nU(       a  Ub  UUS'   U R                  R$                  " S$UUU R&                  US.UD6nU=(       d    SSS.n0 U l        0 nUR+                  5       S:X  a!  [-        [/        U5      5      UU	(       a  SOS'   O7UR+                  5       S:X  a  [-        [/        U5      5      US'   O[        S5      eU R0                  S    H%  n[        R                  SU5        U" XU5      u  pnM'     U R2                  " S$UUU
UUUUUS.UD6n[        R                  SUR4                  5        [        R                  SUR2                  R6                  5        [        R                  SUR2                  R8                  5        [        R                  SUR2                  R:                  5        [        R                  SUR8                  UR<                  5        [        R                  S[?        U R0                  S    5      5        U R0                  S     H!  n[        R                  S!U5        U" U5      nM#     U R                  RA                  UR<                  U RB                  S"9  U R                  R(                  U l        [        R                  S#U R(                  5        U R(                  $ )%a	  Generic method for fetching an access token from the token endpoint.

If you are using the MobileApplicationClient you will want to use
`token_from_fragment` instead of `fetch_token`.

The current implementation enforces the RFC guidelines.

:param token_url: Token endpoint URL, must use HTTPS.
:param code: Authorization code (used by WebApplicationClients).
:param authorization_response: Authorization response URL, the callback
                               URL of the request back to you. Used by
                               WebApplicationClients instead of code.
:param body: Optional application/x-www-form-urlencoded body to add the
             include in the token request. Prefer kwargs over body.
:param auth: An auth tuple or method as accepted by `requests`.
:param username: Username required by LegacyApplicationClients to appear
                 in the request body.
:param password: Password required by LegacyApplicationClients to appear
                 in the request body.
:param method: The HTTP method used to make the request. Defaults
               to POST, but may also be GET. Other methods should
               be added as needed.
:param force_querystring: If True, force the request body to be sent
    in the querystring instead.
:param timeout: Timeout of the request in seconds.
:param headers: Dict to default request headers with.
:param verify: Verify SSL certificate.
:param proxies: The `proxies` argument is passed onto `requests`.
:param include_client_id: Should the request body include the
                          `client_id` parameter. Default is `None`,
                          which will attempt to autodetect. This can be
                          forced to always include (True) or never
                          include (False).
:param client_secret: The `client_secret` paired to the `client_id`.
                      This is generally required unless provided in the
                      `auth` tuple. If the value is `None`, it will be
                      omitted from the request, however if the value is
                      an empty string, an empty string will be sent.
:param cert: Client certificate to send for OAuth 2.0 Mutual-TLS Client
             Authentication (draft-ietf-oauth-mtls). Can either be the
             path of a file containing the private key and certificate or
             a tuple of two filenames for certificate and key.
:param kwargs: Extra parameters to include in the token request.
:return: A token dict
r2   z?Please supply either code or authorization_response parameters.zFCode verifier is not found, authorization URL must be generated beforerg   zQ`LegacyApplicationClient` requires both the `username` and `password` parameters.zGThe required parameter `username` was supplied, but `password` was not.usernamepasswordFTzIEncoding `client_id` "%s" with `client_secret` as Basic auth credentials. client_secret)codebodyr1   include_client_idapplication/json!application/x-www-form-urlencodedAcceptzContent-TypePOSTparamsdataGETz%The method kwarg must be POST or GET.r.   z&Invoking access_token_request hook %s.)methodrm   timeoutheadersr:   verifyproxiescertz0Request to fetch token completed with status %s.zRequest url was %szRequest headers were %szRequest body was %s(Response headers were %s and content %s.!Invoking %d token response hooks.r*   Invoking hook %s.r?   zObtained token %s.r&   )"r	   r   r/   parse_request_uri_responser3   rv   
isinstancer   
ValueErrorr7   rj   r   r=   rH   rI   requestsr:   HTTPBasicAuthprepare_request_bodyr1   r   upperdictr   r<   requeststatus_coderm   r   rw   textlenparse_request_body_responser?   )r   	token_urlrv   authorization_responserw   r:   rr   rs   r   force_querystringr   r   r   r   rx   ru   r   rA   r=   request_kwargshookr'   s                         r   fetch_tokenOAuth2Session.fetch_token   s   B #9--(**.LL33&kk 4  <<$$D*T\\3GHH<<$$D X  ::""* \  '+&9&9F?# dll$;<< <   .  !)F:!)F:  !($)! !, NN	II5!
 6C5NMTVM#==66y-PD (*7'||00 
**/	

 
  
(?
 
<<>V#HL$IN'88fE \\^u$'+IdO'<N8$DEE(()?@DII>E15N2.I A LL 



 

 			DammT		&		6		+QYY->->?		'8		<aiiP		/$$%<=>	
 (()@ADII)40QA B 	00tzz0J\\''
		&

3zzr   c                     U R                   R                  XR                  S9  U R                   R                  U l        U R                  $ )zParse token from the URI fragment, used by MobileApplicationClients.

:param authorization_response: The full URL of the redirect back to you
:return: A token dict
rq   )r/   r   r3   r   )r   r   s     r   token_from_fragment!OAuth2Session.token_from_fragment  s?     	//"++ 	0 	
 \\''
zzr   c	                    U(       d  [        S5      e[        U5      (       d
  [        5       eU=(       d    U R                  R	                  S5      n[
        R                  SU R                  5        U	R                  U R                  5        U R                  R                  " SX2U R                  S.U	D6n[
        R                  SU5        Uc  SSS.nU R                  S	    H%  n
[
        R                  S
U
5        U
" XU5      u  pnM'     U R                  U[        [        U5      5      UUUUSUS9n[
        R                  SUR                   5        [
        R                  SUR"                  UR$                  5        [
        R                  S['        U R                  S   5      5        U R                  S    H!  n
[
        R                  SU
5        U
" U5      nM#     U R                  R)                  UR$                  U R                  S9U l        SU R                  ;  a#  [
        R                  S5        X R                  S'   U R                  $ )a  Fetch a new access token using a refresh token.

:param token_url: The token endpoint, must be HTTPS.
:param refresh_token: The refresh_token to use.
:param body: Optional application/x-www-form-urlencoded body to add the
             include in the token request. Prefer kwargs over body.
:param auth: An auth tuple or method as accepted by `requests`.
:param timeout: Timeout of the request in seconds.
:param headers: A dict of headers to be used by `requests`.
:param verify: Verify SSL certificate.
:param proxies: The `proxies` argument will be passed to `requests`.
:param kwargs: Extra parameters to include in the token request.
:return: A token dict
z'No token endpoint set for auto_refresh.refresh_tokenz*Adding auto refresh key word arguments %s.)rw   r   r?   z&Prepared refresh token request body %sry   rz   r{   r-   z'Invoking refresh_token_request hook %s.T)r   r:   r   r   r   withhold_tokenr   z2Request to refresh token completed with status %s.r   r   r+   r   r   z)No new refresh token given. Re-using old.r&   )r   r	   r   r   getrH   rI   r5   updater/   prepare_refresh_bodyr?   r<   postr   r   r   r   r   r   r   )r   r   r   rw   r:   r   r   r   r   rA   r   r'   s               r   r   OAuth2Session.refresh_token  s   4 FGG"9--(**%H)H		8$:R:R	
 	d../||00 
$**
HN
 			:DA?,!DG
 (()@ADII?F'+I'E$I B IIio&  	
 			FV		<aiiP		/$$%=>?	
 (()ABDII)40QA C \\==affDJJ=W
$**,IIAB*7JJ'zzr   c	                   > [        U5      (       d
  [        5       eU R                  (       a  U(       d  [        R	                  S[        U R                  S   5      5        U R                  S    H%  n
[        R	                  SU
5        U
" X$U5      u  p$nM'     [        R	                  SU R                  5         U R                  R                  X!X4S9u  p$n[        R	                  SX!5        [        R	                  SXC5        [        R	                  SU	5        [$        [&        U ]R  " X4XCUS.U	D6$ ! [         Ga    U R                  (       Ga  [        R	                  SU R                  5        U	R                  SS5      nU(       a?  U(       a8  Uc5  [        R	                  S	U5        [        R                  R                  Xg5      nU R                  " U R                  4SU0U	D6nU R                   (       aQ  [        R	                  S
XR                   5        U R!                  U5        U R                  R                  X!X4S9u  p$n GNp[#        U5      ee f = f)z<Intercept all requests and add the OAuth 2 token if present.z-Invoking %d protected resource request hooks.r,   r   zAdding token %s to request.)http_methodrw   r   z1Auto refresh is set, attempting to refresh at %s.r:   NzEEncoding client_id "%s" with client_secret as Basic auth credentials.zUpdating token to %s using %s.z"Requesting url %s using method %s.z Supplying headers %s and data %sz&Passing through key word arguments %s.)r   r   files)r	   r   r   rH   rI   r   r<   r/   	add_tokenr   r4   popr   r:   r   r   r6   r   r   r    r   )r   r   rm   r   r   r   r=   ru   r   rA   r   r:   r   r   s                r   r   OAuth2Session.request  s    #3''(**::nII?D(()<=> ,,-@A		-t4%)#%="d B II3TZZ@"%)\\%;%;$ &< &"dF 			6D		4gD		:FC]D1
!(5
DJ
 	
E % (((IIK-- "::fd3D ]		c%  (}}::9T ..--48<BE ))		<eEWEW **51-1\\-C-C$ .D .*d +511;s   9D0 0DIIc                     XR                   ;  a  [        SXR                   5      eU R                   U   R                  U5        g)a  Register a hook for request/response tweaking.

Available hooks are:
    access_token_response invoked before token parsing.
    refresh_token_response invoked before refresh token parsing.
    protected_request invoked before making a request.
    access_token_request invoked before making a token fetch request.
    refresh_token_request invoked before making a refresh request.

If you find a new hook is needed please send a GitHub PR request
or open an issue.
zHook type %s is not in %s.N)r<   r   add)r   	hook_typer   s      r   register_compliance_hook&OAuth2Session.register_compliance_hook:  sC     000,i9M9M  	Y'++D1r   )r/   rj   r7   r0   r3   r:   r5   r4   r<   r1   r2   r   r6   )
NNNNNNNNNNr   )NNrt   NNNr}   FNNNNNNN)Nrt   NNNNN)NNFNNN)r   r   r   r   __doc__r   propertyr?   setterrK   r=   deleterr   r[   rb   rn   r   r   r   r   r   r   r   r   s   @r   r    r       s   &  D
L   \\  8 8 ' ' # # 4 4 \\6 6 ; ; * * & & ' '
> ##Ob
 Mf B
H2 2r   r    )loggingoauthlib.commonr   r   oauthlib.oauth2r   r   r   r   r	   r   	getLoggerr   rH   Warningr   Sessionr    r&   r   r   <module>r      sG     5 H 3 B !7 y2H$$ y2r   