
    rhh                         d Z ddlZ	 ddlZddlZdZ	 ddlZ	 ddlZddl	ZdZ
ddZddZd Zd Zd	 Zd
 Zd Zd Zy# e$ r dZY 4w xY w# e$ r dZY <w xY w# e$ r dZ
Y >w xY w)z=Helpers for authentication using oauth2client or google-auth.    NTFc                 r    t         r't        j                  j                  | ||      \  }}|S t	        d      )z'Returns credentials loaded from a file.scopesquota_project_idzAclient_options.credentials_file is only supported in google-auth.)HAS_GOOGLE_AUTHgoogleauthload_credentials_from_fileEnvironmentError)filenamer   r   credentials_s        h/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/googleapiclient/_auth.pycredentials_from_filer   )   sC    ??V6F @ 
Q O
 	
    c                     t         r&t        j                  j                  | |      \  }}|S t        r7| |t        d      t        j                  j                  j                         S t        d      )z(Returns Application Default Credentials.r   zwclient_options.scopes and client_options.quota_project_id are not supported in oauth2client.Please install google-auth.zZNo authentication library is available. Please install either google-auth or oauth2client.)
r   r   r	   defaultHAS_OAUTH2CLIENTr   oauth2clientclientGoogleCredentialsget_application_default)r   r   r   r   s       r   default_credentialsr   6   s    ,,,< - 
Q 	!1!=".  ""44LLNN+
 	
r   c                 (   t         rXt        | t        j                  j                  j
                        r*t        j                  j                  j                  | |      S 	 | j                         r| j                  |      S | S # t        $ r | cY S w xY w)a  Scopes the credentials if necessary.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to scope.
        scopes (Sequence[str]): The list of scopes.

    Returns:
        Union[google.auth.credentials.Credentials,
            oauth2client.client.Credentials]: The scoped credentials.
    )
r   
isinstancer   r	   r   Credentialswith_scopes_if_requiredcreate_scoped_requiredcreate_scopedAttributeError)r   r   s     r   with_scopesr!   K   sz     :k6;;3J3J3V3VW{{&&>>{FSS	113"0088"" 		s     B B BBc                     ddl m} t        r[t        | t        j
                  j                  j                        r-t        t        d      t        j                  |  |             S | j                   |             S )aa  Returns an http client that is authorized with the given credentials.

    Args:
        credentials (Union[
            google.auth.credentials.Credentials,
            oauth2client.client.Credentials]): The credentials to use.

    Returns:
        Union[httplib2.Http, google_auth_httplib2.AuthorizedHttp]: An
            authorized http client.
    r   )
build_httpzCredentials from google.auth specified, but google-api-python-client is unable to use these credentials unless google-auth-httplib2 is installed. Please install google-auth-httplib2.http)googleapiclient.httpr#   r   r   r   r	   r   r   google_auth_httplib2
ValueErrorAuthorizedHttp	authorize)r   r#   s     r   authorized_httpr+   d   se     0:k6;;3J3J3V3VW'(  $22;Z\RR$$Z\22r   c                     t        j                         }t        rTt        | t        j
                  j                  j                        r&t        j                  |      }| j                  |      S | j                  |      S N)httplib2Httpr   r   r   r	   r   r   r'   Requestrefresh)r   refresh_httprequests      r   refresh_credentialsr4      s]    
 ==?L:k6;;3J3J3V3VW&..|<""7++""<00r   c                 P    t        |       st        |        | j                  |      S r-   )is_validr4   apply)r   headerss     r   apply_credentialsr9      s#    K K(W%%r   c                     t         r:t        | t        j                  j                  j
                        r| j                  S | j                  d uxr | j                   S r-   )	r   r   r   r	   r   r   validaccess_tokenaccess_token_expired)r   s    r   r6   r6      sP    :k6;;3J3J3V3VW    $$D0 5444	
r   c                     | y t        | j                  d      r| j                  j                  S t        | d      r0t        | j                  t        j
                        s| j                  S y )Nr   )hasattrr3   r   r   r.   r   r$   s    r   get_credentials_from_httpr@      s[    |	}	-||'''	}	%j(../ r   )NN)__doc__r.   google.authr   google.auth.credentialsr   ImportErrorr'   r   oauth2client.clientr   r   r   r!   r+   r4   r9   r6   r@    r   r   <module>rG      s    D "O 



*236
1&

K  O
      s1   
= A
 
A AA
AAA! A!