
    D6iV&                         d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZ dd	lmZmZmZmZ dd
lmZ  e j2                  e      Z G d de      Zy)    N)current_appredirectrequesturl_for)
to_unicode)SIGNATURE_HMACSIGNATURE_TYPE_AUTH_HEADER)TokenMissingTokenRequestDenied)cached_property)Response   )BaseOAuthConsumerBlueprintoauth_authorizedoauth_before_loginoauth_error)OAuth1Sessionc                   r    e Zd ZdZ	 	 d
eedddddddddddddddddddddddZed        ZddZ	d Z
d	 Zy)OAuth1ConsumerBlueprintzU
    A subclass of :class:`flask.Blueprint` that sets up OAuth 1 authentication.
    NF)signature_methodsignature_typersa_keyclient_classforce_include_bodystatic_folderstatic_url_pathtemplate_folder
url_prefix	subdomainurl_defaults	root_path	login_urlauthorized_urlbase_urlrequest_token_urlauthorization_urlaccess_token_urlredirect_urlredirect_tosession_classstoragerule_kwargsc                b   t        j                  | |||
||||||||||       || _        |xs t        | _        || _        || _        || _        || _        || _	        || _
        |	| _        || _        || _        || _        || _        || _        || _        | j%                  | j&                         y)a  
        Most of the constructor arguments are forwarded either to the
        :class:`flask.Blueprint` constructor or the
        :class:`requests_oauthlib.OAuth1Session` constructor, including
        ``**kwargs`` (which is forwarded to
        :class:`~requests_oauthlib.OAuth1Session`).
        Only the arguments that are relevant to Flask-Dance are documented here.

        Args:
            base_url: The base URL of the OAuth provider.
                If specified, all URLs passed to this instance will be
                resolved relative to this URL.
            request_token_url: The URL specified by the OAuth provider for
                obtaining a
                `request token <http://oauth.net/core/1.0a/#auth_step1>`_.
                This can be an fully-qualified URL, or a path that is
                resolved relative to the ``base_url``.
            authorization_url: The URL specified by the OAuth provider for
                the user to
                `grant token authorization <http://oauth.net/core/1.0a/#auth_step2>`_.
                This can be an fully-qualified URL, or a path that is
                resolved relative to the ``base_url``.
            access_token_url: The URL specified by the OAuth provider for
                obtaining an
                `access token <http://oauth.net/core/1.0a/#auth_step3>`_.
                This can be an fully-qualified URL, or a path that is
                resolved relative to the ``base_url``.
            login_url: The URL route for the ``login`` view that kicks off
                the OAuth dance. This string will be
                :ref:`formatted <python:formatstrings>`
                with the instance so that attributes can be interpolated.
                Defaults to ``/{bp.name}``, so that the URL is based on the name
                of the blueprint.
            authorized_url: The URL route for the ``authorized`` view that
                completes the OAuth dance. This string will be
                :ref:`formatted <python:formatstrings>`
                with the instance so that attributes can be interpolated.
                Defaults to ``/{bp.name}/authorized``, so that the URL is
                based on the name of the blueprint.
            redirect_url: When the OAuth dance is complete,
                redirect the user to this URL.
            redirect_to: When the OAuth dance is complete,
                redirect the user to the URL obtained by calling
                :func:`~flask.url_for` with this argument. If you do not specify
                either ``redirect_url`` or ``redirect_to``, the user will be
                redirected to the root path (``/``).
            session_class: The class to use for creating a Requests session
                between the consumer (your website) and the provider (e.g.
                Google). Defaults to
                :class:`~flask_dance.consumer.requests.OAuth1Session`.
            storage: A token storage class, or an instance of a token storage
                class, to use for this blueprint. Defaults to
                :class:`~flask_dance.consumer.storage.session.SessionStorage`.
            rule_kwargs (dict, optional): Additional arguments that should be passed when adding
                the login and authorized routes. Defaults to ``None``.
        )r   r   r   r   r   r    r!   r"   r#   r+   r,   N)r   __init__r$   r   r*   
client_keyclient_secretr   r   r   r   r   kwargsr%   r&   r'   r(   r)   teardown_app_requestteardown_session)selfnameimport_namer/   r0   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r1   s                                ^/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_dance/consumer/oauth1.pyr.   z OAuth1ConsumerBlueprint.__init__   s    p 	#++'++!%)#	
" !*;m %* 0,("4 "3!2 0(&!!$"7"78    c                      | j                   d| j                  | j                  | j                  | j                  | j
                  | j                  | j                  | | j                  d	| j                  S )z
        This is a session between the consumer (your website) and the provider
        (e.g. Google). It is *not* a session between a user of your website
        and your website.
        :return:
        )	r/   r0   r   r   r   r   r   	blueprintr$    )
r*   r/   r0   r   r   r   r   r   r$   r1   )r4   s    r7   sessionzOAuth1ConsumerBlueprint.session   sq     "t!! 
,,!22..LL**#66]]
 kk
 	
r8   c                 (    	 | ` y # t        $ r Y y w xY wN)r<   KeyError)r4   	exceptions     r7   r3   z(OAuth1ConsumerBlueprint.teardown_session   s    	 		s    	c                    t        dd      }t        |      | j                  j                  j                  _        	 | j                  j                  | j                  d       | j                  j%                  | j$                        }t'        j                  | |       t#        |      S # t        $ r}|j                  d   }t        |dd       }t        j                  d|       t        j                  | ||	       | j                  r| j                  }n$| j                   rt        | j                         }nd
}t#        |      cY d }~S d }~ww xY w)Nz.authorizedT)	_externalFshould_load_tokenr   responsezOAuth 1 request token error: %smessagerE   /)url)r   r   r<   _clientclientcallback_urifetch_request_tokenr%   r   argsgetattrlogwarningr   sendr(   r)   r   r&   r   )r4   rL   errrG   rE   next_urlrI   s          r7   loginzOAuth1ConsumerBlueprint.login   s   }=3=l3K##0	&LL,,&&% - " ll,,T-C-CD#.}! " 	&hhqkGsJ5HKK97CT7XF  ,,!!"4#3#34H%%	&s   'B+ +	E4BEEEc                    | j                   r| j                   }n$| j                  rt        | j                        }nd}	 | j                  j	                  t
        j                         	 | j                  j                  | j                   d      }t%        j                  | |	      xs g }d
}|D ]1  \  }}	t'        |	t(        t*        j,                  f      r|	c S |	dk(  s0d}3 |r|| _        t        |      S # t        $ r_}|j                  d   }t        |dd      }t        j                  d|       t        j                  | ||       t        |      cY d}~S d}~ww xY w# t"        $ r_}|j                  d   }t        |dd      }t        j                  d|       t        j                  | ||       t        |      cY d}~S d}~ww xY w)z
        This is the route/function that the user will be redirected to by
        the provider (e.g. Google) after the user has logged into the
        provider's website and authorized your app to access their account.
        rH   r   rE   NzOAuth 1 access token error: %srF   FrC   )tokenT)r(   r)   r   r<   parse_authorization_responser   rI   r
   rN   rO   rP   rQ   r   rR   r   fetch_access_tokenr'   
ValueErrorr   
isinstancer   r   response_classrW   )
r4   rT   rS   rG   rE   rW   results	set_tokenfuncrets
             r7   
authorizedz"OAuth1ConsumerBlueprint.authorized   s    ((Ht//0HH	&LL55gkkB
	&LL33%% 4 E #''E:@b	  	"ID##+*D*DEF
e|!			" DJ!!;  	&hhqkGsJ5HKK8'BT7XFH%%	&  	&hhqkGsJ5HKK8'BT7XFH%%	&s=   )C7 )'E" 7	E AEEE"	G
+AG?G
G
)NNr>   )__name__
__module____qualname____doc__r   r	   r.   r   r<   r3   rU   ra   r;   r8   r7   r   r      s     }9 (1 ;}9~ 
 
(4,"r8   r   )loggingflaskr   r   r   r   oauthlib.commonr   oauthlib.oauth1r   r	    requests_oauthlib.oauth1_sessionr
   r   werkzeug.utilsr   werkzeug.wrappersr   baser   r   r   r   requestsr   	getLoggerrb   rP   r   r;   r8   r7   <module>rp      sM     9 9 & F M * &  $g!e"8 e"r8   