Ë
    +Ñ¦hò  ã                   óˆ   — d dl mZ d dlmZ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	e	«      Z G d
„ de«      Z
y)é    ©Úwraps)ÚredirectÚurl_for)Ú
to_unicode)ÚOAuth1Session)ÚOAuth2Session)Ú	URLObject)Úcached_propertyc                   óv   ‡ — e Zd ZdZd	ˆ fd„	Zed„ «       Zd„ Zeˆ fd„«       Z	ed„ «       Z
ˆ fd„Z	 d
ˆ fd„	Zˆ xZS )r   aì  
    A :class:`requests.Session` subclass that can do some special things:

    * lazy-loads OAuth1 tokens from the storage via the blueprint
    * handles OAuth1 authentication
      (from :class:`requests_oauthlib.OAuth1Session` superclass)
    * has a ``base_url`` property used for relative URL resolution

    Note that this is a session between the consumer (your website) and the
    provider (e.g. Google), and *not* a session between a user of your website
    and your website.
    c                 óR   •— t        ‰| �  |i |¤Ž || _        t        |«      | _        y ©N)ÚsuperÚ__init__Ú	blueprintr
   Úbase_url©Úselfr   r   ÚargsÚkwargsÚ	__class__s        €úU/var/www/timesheet/venv/lib/python3.12/site-packages/flask_dance/consumer/requests.pyr   zOAuth1Session.__init__   s(   ø€ Ü‰Ñ˜$Ð) &Ò)Ø"ˆŒÜ! (Ó+ˆ�ó    c                 ó.   — | j                   j                  S ©zX
        Get and set the values in the OAuth token, structured as a dictionary.
        ©r   Útoken©r   s    r   r   zOAuth1Session.token   ó   € ð
 �~‰~×#Ñ#Ð#r   c                 óÎ   — | j                   }|rWd|v rSd|v rOt        |d   «      | j                  j                  _        t        |d   «      | j                  j                  _        yy)NÚoauth_tokenÚoauth_token_secretTF)r   r   ÚauthÚclientÚresource_owner_keyÚresource_owner_secret)r   Úts     r   Ú
load_tokenzOAuth1Session.load_token%   s^   € Ø�J‰JˆÙ� !Ñ#Ð(<ÀÑ(Aô 3=¸Q¸}Ñ=MÓ2NˆD�I‰I×ÑÔ/Ü5?ÀÐBVÑ@WÓ5XˆD�I‰I×ÑÔ2ØØr   c                 ó8   •— | j                  «        t        ‰| �  S ©a  This is the property used when you have a statement in your code
        that reads "if <provider>.authorized:", e.g. "if google.authorized:".

        The way it works is kind of complicated: this function just tries
        to load the token, and then the 'super()' statement basically just
        tests if the token exists (see BaseOAuth1Session.authorized).

        To load the token, it calls the load_token() function within this class,
        which in turn checks the 'token' property of this class (another
        function), which in turn checks the 'token' property of the blueprint
        (see base.py), which calls 'storage.get()' to actually try to load
        the token from the cache/db (see the 'get()' function in
        storage/sqla.py).
        ©r(   r   Ú
authorized©r   r   s    €r   r,   zOAuth1Session.authorized/   ó   ø€ ð  	�‰ÔÜ‰wÑ!Ð!r   c                 ó   ‡ — ˆ fd„}|S )a   
        .. versionadded:: 1.3.0

        This is a decorator for a view function. If the current user does not
        have an OAuth token, then they will be redirected to the
        :meth:`~flask_dance.consumer.oauth1.OAuth1ConsumerBlueprint.login`
        view to obtain one.
        c                 ó2   •‡ — t        ‰ «      ˆ ˆfd„«       }|S )Nc                  ó†   •— ‰j                   s-‰j                  j                  › d�}t        t	        |«      «      S  ‰| i |¤ŽS ©Nz.login©r,   r   Únamer   r   ©r   r   ÚendpointÚfuncr   s      €€r   Úcheck_authorizationzROAuth1Session.authorization_required.<locals>.wrapper.<locals>.check_authorizationN   óA   ø€ à—’Ø"&§.¡.×"5Ñ"5Ð!6°fÐ=�HÜ#¤G¨HÓ$5Ó6Ð6Ù˜TÐ, VÑ,Ð,r   r   ©r7   r8   r   s   ` €r   Úwrapperz5OAuth1Session.authorization_required.<locals>.wrapperM   ó!   ù€ Ü�4‹[ô-ó ð-ð 'Ð&r   © ©r   r;   s   ` r   Úauthorization_requiredz$OAuth1Session.authorization_requiredB   ó   ø€ ô	'ð ˆr   c                 óŽ   •— | j                   r*| j                   j                  |j                  «      |_        t        ‰| �  |«      S r   )r   ÚrelativeÚurlr   Úprepare_request)r   Úrequestr   s     €r   rD   zOAuth1Session.prepare_requestY   s4   ø€ Ø�=Š=ØŸ-™-×0Ñ0°·±Ó=ˆGŒKÜ‰wÑ& wÓ/Ð/r   c                 óP   •— |r| j                  «        t        ‰| �  d||||dœ|¤ŽS )N)ÚmethodrC   ÚdataÚheadersr=   )r(   r   rE   )r   rG   rC   rH   rI   Úshould_load_tokenr   r   s          €r   rE   zOAuth1Session.request^   s9   ø€ ñ Ø�O‰OÔÜ‰w‰ð 
Ø˜s¨°wñ
ØBHñ
ð 	
r   ©NN)NNT)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r(   Úpropertyr,   r?   rD   rE   Ú__classcell__©r   s   @r   r   r      sd   ø„ ñõ,ð
 ñ$ó ð$òð ó"ó ð"ð$ ñó ðô,0ð GK÷
ñ 
r   r   c                   óz   ‡ — e Zd ZdZd	ˆ fd„	Zed„ «       Zd„ Zed„ «       Z	eˆ fd„«       Z
ed„ «       Zd	ˆ fd„	Zˆ xZS )
r	   aì  
    A :class:`requests.Session` subclass that can do some special things:

    * lazy-loads OAuth2 tokens from the storage via the blueprint
    * handles OAuth2 authentication
      (from :class:`requests_oauthlib.OAuth2Session` superclass)
    * has a ``base_url`` property used for relative URL resolution

    Note that this is a session between the consumer (your website) and the
    provider (e.g. Google), and *not* a session between a user of your website
    and your website.
    c                 óV   •— t        ‰| �  |i |¤Ž || _        t        |«      | _        | `y r   )r   r   r   r
   r   r   r   s        €r   r   zOAuth2Session.__init__v   s-   ø€ Ü‰Ñ˜$Ð) &Ò)Ø"ˆŒÜ! (Ó+ˆŒØ‰Jr   c                 ó.   — | j                   j                  S r   r   r   s    r   r   zOAuth2Session.token|   r   r   c                 óž   — | j                   | j                  _         | j                   r&| j                  j                  | j                   «       yy)NTF)r   Ú_clientÚpopulate_token_attributesr   s    r   r(   zOAuth2Session.load_tokenƒ   s5   € Ø!ŸZ™Zˆ�‰ÔØ�:Š:Ø�L‰L×2Ñ2°4·:±:Ô>ØØr   c                 óT   — | j                   xr | j                   j                  d«      S )zD
        Returns the ``access_token`` from the OAuth token.
        Úaccess_token)r   Úgetr   s    r   rZ   zOAuth2Session.access_tokenŠ   s    € ð
 �z‰zÒ<˜dŸj™jŸn™n¨^Ó<Ð<r   c                 ó8   •— | j                  «        t        ‰| �  S r*   r+   r-   s    €r   r,   zOAuth2Session.authorized‘   r.   r   c                 ó   ‡ — ˆ fd„}|S )a   
        .. versionadded:: 1.3.0

        This is a decorator for a view function. If the current user does not
        have an OAuth token, then they will be redirected to the
        :meth:`~flask_dance.consumer.oauth2.OAuth2ConsumerBlueprint.login`
        view to obtain one.
        c                 ó2   •‡ — t        ‰ «      ˆ ˆfd„«       }|S )Nc                  ó†   •— ‰j                   s-‰j                  j                  › d�}t        t	        |«      «      S  ‰| i |¤ŽS r2   r3   r5   s      €€r   r8   zROAuth2Session.authorization_required.<locals>.wrapper.<locals>.check_authorization°   r9   r   r   r:   s   ` €r   r;   z5OAuth2Session.authorization_required.<locals>.wrapper¯   r<   r   r=   r>   s   ` r   r?   z$OAuth2Session.authorization_required¤   r@   r   c           
      óî   •— | j                   r| j                   j                  |«      }| j                  «        t        ‰| �  d||||| j
                  j                  | j
                  j                  dœ|¤ŽS )N)rG   rC   rH   rI   Ú	client_idÚclient_secretr=   )r   rB   r(   r   rE   r   ra   rb   )r   rG   rC   rH   rI   r   r   s         €r   rE   zOAuth2Session.request»   sn   ø€ Ø�=Š=Ø—-‘-×(Ñ(¨Ó-ˆCà�‰ÔÜ‰w‰ð 
ØØØØØ—n‘n×.Ñ.ØŸ.™.×6Ñ6ñ
ð ñ
ð 	
r   rK   )rL   rM   rN   rO   r   r   r   r(   rP   rZ   r,   r?   rE   rQ   rR   s   @r   r	   r	   h   sl   ø„ ñõð ñ$ó ð$òð ñ=ó ð=ð ó"ó ð"ð$ ñó ð÷,
ñ 
r   r	   N)Ú	functoolsr   Úflaskr   r   Úoauthlib.commonr   Úrequests_oauthlibr   ÚBaseOAuth1Sessionr	   ÚBaseOAuth2SessionÚ	urlobjectr
   Úwerkzeug.utilsr   r=   r   r   ú<module>rk      s9   ðÝ ç #Ý &Ý @Ý @Ý Ý *ôZ
Ð%ô Z
ôz`
Ð%õ `
r   