o
    |V
hö  ã                   @   s–   d dl mZ d dlmZ d dlZd dlmZ d dlZd dlm	Z	 eƒ  e 
d¡Ze	 ¡ Ze	eƒZdedefd	d
„Zdedefdd„Zdefdd„ZdS )é    )Úid_token)ÚrequestsN)Úload_dotenv)ÚFernetÚGOOGLE_CLIENT_IDÚrefresh_tokenÚreturnc                 C   ó   t  |  ¡ ¡ ¡ S ©N)Úcipher_suiteÚencryptÚencodeÚdecode)r   © r   ú:/var/www/html/moveengine/app/v1/libraries/googleconnect.pyÚencrypt_refresh_token   ó   r   Úencrypted_refresh_tokenc                 C   r	   r
   )r   Údecryptr   r   )r   r   r   r   Údecrypt_refresh_token   r   r   Útokenc              
   C   s„   z.t  | t ¡ t¡}|d dvrtdƒ‚d}t|ƒ}|d | d¡| d¡|d |d	œ}|W S  tyA } zW Y d }~d S d }~ww )
NÚiss)zaccounts.google.comzhttps://accounts.google.comzWrong issuer.z!your-oauth-flow-needs-to-set-thisÚemailÚnameÚpictureÚsub)r   r   r   Ú	google_idr   )r   Úverify_oauth2_tokenr   ÚRequestr   Ú
ValueErrorr   Úget)r   Úidinfor   r   Ú	user_infoÚerrorr   r   r   Úverify_google_token   s"   û€þr$   )Úgoogle.oauth2r   Úgoogle.auth.transportr   ÚosÚdotenvr   ÚloggingÚcryptography.fernetr   Úgetenvr   Úgenerate_keyÚ
fernet_keyr   Ústrr   r   r$   r   r   r   r   Ú<module>   s    
