
    ,6i
                        d Z ddlZddlmZ ddl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 ddlmZmZmZ ddlmZmZ ddlmZ  eej:                  ej<                  d eeej>                  ed            Z  e	jB                  e       d        Z" eejF                  ejH                  g d eeej>                  ed            Z% e	jB                  e%      d        Z&y)z)
Copyright (c) 2019 - present AppSeed.us
    N)current_app)current_user
login_user)oauth_authorized)githubmake_github_blueprint)googlemake_google_blueprint)SQLAlchemyStorage)NoResultFound)Config   )UsersdbOAuth)redirecturl_for)flashuserF)r   user_required)	client_idclient_secretscopestoragec                    t        j                  d      }|j                  rR|j                         }|d   }t        j
                  j                  |      }	 |j                         }t        |       y y # t        $ rf t	               }d|z   |_
        ||_        t        j                  j                  |       t        j                  j                          t        |       Y y w xY w)Nz/userlogin)oauth_githubz(gh))r   getokjsonr   query	filter_byoner   r   usernamer   r   sessionaddcommit)	blueprinttokeninfoaccount_infor$   r!   r   s          :/home/azureuser/techstart-app/apps/authentication/oauth.pygithub_logged_inr-       s    ::gDwwyy{#G,%%8%<	99;Dt   	 !&D & 1DM (D JJNN4 JJt	s   A5 5A,C$#C$)openidz.https://www.googleapis.com/auth/userinfo.emailz0https://www.googleapis.com/auth/userinfo.profilec                    t        j                  d      }|j                  rW|j                         }|d   }|d   }t        j
                  j                  |      }	 |j                         }t        |       y y # t        $ rm t	               }d|z   |_
        ||_        ||_        t        j                  j                  |       t        j                  j!                          t        |       Y y w xY w)Nz/oauth2/v1/userinfo
given_nameemail)oauth_googlez(google))r	   r   r   r    r   r!   r"   r#   r   r   r$   r2   r1   r   r%   r&   r'   )r(   r)   r*   r+   r$   r1   r!   r   s           r,   google_logged_inr3   R   s    ::+,Dwwyy{#L1#G,%%8%<	99;Dt   	 %D *X 5DM (D %DJ JJNN4 JJt	s   A: :A3C0/C0)'__doc__osflaskr   appflask_loginr   r   flask_dance.consumerr   flask_dance.contrib.githubr   r   flask_dance.contrib.googler	   r
   !flask_dance.consumer.storage.sqlar   sqlalchemy.orm.excr   apps.configr   modelsr   r   r   r   r   r   	GITHUB_IDGITHUB_SECRETr%   github_blueprintconnect_viar-   	GOOGLE_IDGOOGLE_SECRETgoogle_blueprintr3        r,   <module>rI      s    
 $ 0 1 D D ? ,  $ $ # (&&


		  ./ 0@ )&&
 


	 " ./ 0rH   