
    D6i                        d dl mZmZmZ d dlmZmZmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ  e	       Zej#                  d      Zej#                  d	      Zej#                  d
      Z G d dej*                  e      Zy)    )ABCMetaabstractmethodabstractproperty)datetime	timedeltatimezoneN)	Namespace)CallbackDict)SessionStorage)getattrdzoauth-authorizedzoauth-before-loginzoauth-errorc                      e Zd ZdddddddddddddZd Zed        Zej                  d        Zej                  d        Zed        Z	e	j                  d	        Z	e	j                  d
        Z	e
d        Zed        Zed        Zy)BaseOAuthConsumerBlueprintN)static_folderstatic_url_pathtemplate_folder
url_prefix	subdomainurl_defaults	root_path	login_urlauthorized_urlstoragerule_kwargsc                2    t        |||||||||		      }t        j                  j                   fi | |
xs d}
|xs d}|xs i }  j                  d
|
j                         d j                  d|   j                  d
|j                         d j                  d| |t                _	        nt        |      r |        _	        n| _	        g  _        i  _         fd}t        |	       _         j                   j                          y )N)	nameimport_namer   r   r   r   r   r   r   z
/{bp.name}z/{bp.name}/authorized)bplogin)ruleendpoint	view_func
authorizedc                 >    	 j                   `y # t        $ r Y y w xY wN)sessiontokenKeyError)dselfs    \/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_dance/consumer/base.pyinvalidate_tokenz=BaseOAuthConsumerBlueprint.__init__.<locals>.invalidate_tokenK   s$    LL& s    	)	on_update )dictflask	Blueprint__init__add_url_ruleformatr   r"   r   r   callablelogged_in_funcsfrom_configr
   configbefore_app_requestload_config)r)   r   r   r   r   r   r   r   r   r   r   r   r   r   	bp_kwargsr+   s   `               r*   r1   z#BaseOAuthConsumerBlueprint.__init__   s9   " #'++!%

	 	  33-	'B+B!'R 	
!!T!*jj	
 		
 	 	
&&$&/!oo	
 		
 ?)+DLg"9DL"DL!	 #-=> 0 01    c                     | j                   j                         D ]q  \  }}t        j                  j                  j                  |      }|s2d|v r/|j                  dd      \  }}t        | |      }t        |||       et        | ||       s y)a  
        Used to dynamically load variables from the Flask application config
        into the blueprint. To tell this blueprint to pull configuration from
        the app, just set key-value pairs in the ``from_config`` dict. Keys
        are the name of the local variable to set on the blueprint object,
        and values are the variable name in the Flask application config.
        For example:

            blueprint.from_config["session.client_id"] = "GITHUB_OAUTH_CLIENT_ID"

        .   N)	r6   itemsr/   current_appr7   getrsplitr   setattr)r)   	local_var
config_varvaluebodytailobjs          r*   r9   z&BaseOAuthConsumerBlueprint.load_configT   s     &*%5%5%;%;%= 
	4!Iz%%,,00<E)#!*!1!1#q!9JD$"4.CCu- D)U3
	4r;   c                     | j                   S )zW
        The :doc:`token storage <storages>` that this blueprint
        uses.
        _storager)   s    r*   r   z"BaseOAuthConsumerBlueprint.storagel   s     }}r;   c                     || _         y r$   rK   )r)   rF   s     r*   r   z"BaseOAuthConsumerBlueprint.storaget   s	    r;   c                     | ` y r$   rK   rM   s    r*   r   z"BaseOAuthConsumerBlueprint.storagex   s    Mr;   c                 D   | j                   j                  |       }|r|j                  d      rq|j                  d      r`t        j                  |d   t        j
                        }|t        j                  t        j
                        z
  }|j                         |d<   |S )a  
        This property functions as pass-through to the token storage.
        If you read from this property, you will receive the current
        value from the token storage. If you assign a value to this
        property, it will get set in the token storage.
        
expires_in
expires_at)r   rA   r   fromtimestampr   utcnowtotal_seconds)r)   _tokenrR   rQ   s       r*   r&   z BaseOAuthConsumerBlueprint.token|   s}     !!$'fjj.6::l3K "//|0DhllSJ#hll8<<&@@J#-#;#;#=F< r;   c                 |   |}|r|j                  d      rot        t        |d               }t        j                  t
        j                        |z   }|j                  t
        j                        j                         |d<   | j                  j                  | |       	 | j                  `y # t        $ r Y y w xY w)NrQ   )seconds)tzinforR   )rA   r   intr   rU   r   rT   replace	timestampr   setr%   r&   r'   )r)   rF   rW   deltarR   s        r*   r&   z BaseOAuthConsumerBlueprint.token   s    fjj. c&*>&?@E!hll3e;J#-#5#5X\\#5#J#T#T#VF< v&	" 		s   "B/ /	B;:B;c                 r    | j                   j                  |        	 | j                  `y # t        $ r Y y w xY wr$   )r   deleter%   r&   r'   rM   s    r*   r&   z BaseOAuthConsumerBlueprint.token   s5    D!	" 		s   * 	66c                     t               )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.
        NotImplementedErrorrM   s    r*   r%   z"BaseOAuthConsumerBlueprint.session        "##r;   c                     t               r$   rc   rM   s    r*   r   z BaseOAuthConsumerBlueprint.login   s    !##r;   c                     t               )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.
        rc   rM   s    r*   r"   z%BaseOAuthConsumerBlueprint.authorized   re   r;   )__name__
__module____qualname__r1   r9   propertyr   setterdeleterr&   r   r%   r   r   r"   r-   r;   r*   r   r      s     @2D40   ^^  __   " \\  ]]  $ $ $ $ $ $r;   r   )	metaclass)abcr   r   r   r   r   r   r/   flask.signalsr	   werkzeug.datastructuresr
   $flask_dance.consumer.storage.sessionr   flask_dance.utilsr   _signalssignaloauth_authorizedoauth_before_loginoauth_errorr0   r   r-   r;   r*   <module>ry      si    9 9 2 2  # 0 ? &;??#56 __%9: oom,h$G h$r;   