
    h!                     8   d Z ddlZddlZddl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
j                    Zg dZ ej        dd	d
g          Z	  G d d          Z G d de          Z G d de          Z G d de          Z G d de          Zd ZdS )zFirebase credentials module.    N)Credentials)requests)credentials)service_account)z.https://www.googleapis.com/auth/cloud-platformz)https://www.googleapis.com/auth/datastorez5https://www.googleapis.com/auth/devstorage.read_writez(https://www.googleapis.com/auth/firebasez/https://www.googleapis.com/auth/identitytoolkitz.https://www.googleapis.com/auth/userinfo.emailAccessTokenInfoaccess_tokenexpiryc                       e Zd ZdZd Zd ZdS )Basez>Provides OAuth2 access tokens for accessing Firebase services.c                     |                                  }|                    t                     t          |j        |j                  S )zFetches a Google OAuth2 access token using this credential instance.

        Returns:
          AccessTokenInfo: An access token obtained using the credential.
        )get_credentialrefresh_requestr   tokenr	   )selfgoogle_creds     ^/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/firebase_admin/credentials.pyget_access_tokenzBase.get_access_token0   s?     ))++H%%%{0+2DEEE    c                     t           )z?Returns the Google credential instance used for authentication.)NotImplementedErrorr   s    r   r   zBase.get_credential:   s    !!r   N)__name__
__module____qualname____doc__r   r    r   r   r   r   -   s;        HHF F F" " " " "r   r   c                   .     e Zd ZdZdef fdZd Z xZS )_ExternalCredentialszLA wrapper for google.auth.credentials.Credentials typed credential instances
credentialc                 V    t                                                       || _        d S Nsuper__init___g_credential)r   r    	__class__s     r   r%   z_ExternalCredentials.__init__A   s'    'r   c                     | j         S )zReturns the underlying Google Credential

        Returns:
          google.auth.credentials.Credentials: A Google Auth credential instance.r&   r   s    r   r   z#_ExternalCredentials.get_credentialE       
 !!r   )r   r   r   r   GoogleAuthCredentialsr%   r   __classcell__r'   s   @r   r   r   >   sZ        VV(#8 ( ( ( ( ( (" " " " " " "r   r   c                   n     e Zd ZdZdZ fdZed             Zed             Zed             Z	d Z
 xZS )Certificatez9A credential initialized from a JSON certificate keyfile.r   c                 H   t                                                       t          |          r>t          |d          5 }t	          j        |          }ddd           n# 1 swxY w Y   n+t          |t                    r|}nt          d| d          |	                    d          | j
        k    rt          d| j
         d          	 t          j                            |t          	          | _        dS # t          $ r}t          d
| d          |d}~ww xY w)a]  Initializes a credential from a Google service account certificate.

        Service account certificates can be downloaded as JSON files from the Firebase console.
        To instantiate a credential from a certificate file, either specify the file path or a
        dict representing the parsed contents of the file.

        Args:
          cert: Path to a certificate file or a dict representing the contents of a certificate.

        Raises:
          IOError: If the specified certificate file doesn't exist or cannot be read.
          ValueError: If the specified certificate is invalid.
        utf-8encodingNzInvalid certificate argument: "z[". Certificate argument must be a file path, or a dict containing the parsed file contents.typezUInvalid service account certificate. Certificate must contain a "type" field set to "".scopesz;Failed to initialize a certificate credential. Caused by: "")r$   r%   _is_file_pathopenjsonload
isinstancedict
ValueErrorget_CREDENTIAL_TYPEr   r   from_service_account_info_scopesr&   )r   cert	json_file	json_dataerrorr'   s        r   r%   zCertificate.__init__Q   s    	 	HdW--- 1 Ii00	1 1 1 1 1 1 1 1 1 1 1 1 1 1 1d## 	HIIG$ G G GH H H ==  D$999B(,(=B B BC C C	c!0!<!V!V' "W "+ "+D 	c 	c 	cVeVVVX X]bc	cs*   A##A'*A'+C> >
D!DD!c                     | j         j        S r"   )r&   
project_idr   s    r   rI   zCertificate.project_idu   s    !,,r   c                     | j         j        S r"   )r&   signerr   s    r   rK   zCertificate.signery   s    !((r   c                     | j         j        S r"   )r&   service_account_emailr   s    r   rM   z!Certificate.service_account_email}   s    !77r   c                     | j         S zReturns the underlying Google credential.

        Returns:
          google.auth.credentials.Credentials: A Google Auth credential instance.r)   r   s    r   r   zCertificate.get_credential   r*   r   )r   r   r   r   rA   r%   propertyrI   rK   rM   r   r,   r-   s   @r   r/   r/   L   s        CC("c "c "c "c "cH - - X- ) ) X) 8 8 X8" " " " " " "r   r/   c                   D     e Zd ZdZ fdZd Zed             Zd Z xZ	S )ApplicationDefaultz(A Google Application Default credential.c                 V    t                                                       d| _        dS )zCreates an instance that will use Application Default credentials.

        The credentials will be lazily initialized when get_credential() or
        project_id() is called. See those methods for possible errors raised.
        Nr#   )r   r'   s    r   r%   zApplicationDefault.__init__   s)     	!r   c                 8    |                                   | j        S )a:  Returns the underlying Google credential.

        Raises:
          google.auth.exceptions.DefaultCredentialsError: If Application Default
              credentials cannot be initialized in the current environment.
        Returns:
          google.auth.credentials.Credentials: A Google Auth credential instance.)_load_credentialr&   r   s    r   r   z!ApplicationDefault.get_credential   s     	!!r   c                 8    |                                   | j        S )a  Returns the project_id from the underlying Google credential.

        Raises:
          google.auth.exceptions.DefaultCredentialsError: If Application Default
              credentials cannot be initialized in the current environment.
        Returns:
          str: The project id.)rU   _project_idr   s    r   rI   zApplicationDefault.project_id   s     	r   c                 |    | j         s4t          j                            t                    \  | _         | _        d S d S )Nr6   )r&   googleauthdefaultrC   rW   r   s    r   rU   z#ApplicationDefault._load_credential   sC    ! 	W39;3F3Fg3F3V3V0D 0 0 0	W 	Wr   )
r   r   r   r   r%   r   rP   rI   rU   r,   r-   s   @r   rR   rR      s~        22" " " " "	" 	" 	" 	  	  X	 W W W W W W Wr   rR   c                   n     e Zd ZdZdZ fdZed             Zed             Zed             Z	d Z
 xZS )RefreshTokenz8A credential initialized from an existing refresh token.authorized_userc                    t                                                       t          |          r>t          |d          5 }t	          j        |          }ddd           n# 1 swxY w Y   n+t          |t                    r|}nt          d| d          |	                    d          | j
        k    rt          d| j
         d          t          j                            |t                    | _        dS )	a  Initializes a credential from a refresh token JSON file.

        The JSON must consist of client_id, client_secret and refresh_token fields. Refresh
        token files are typically created and managed by the gcloud SDK. To instantiate
        a credential from a refresh token file, either specify the file path or a dict
        representing the parsed contents of the file.

        Args:
          refresh_token: Path to a refresh token file or a dict representing the contents of a
              refresh token file.

        Raises:
          IOError: If the specified file doesn't exist or cannot be read.
          ValueError: If the refresh token configuration is invalid.
        r1   r2   Nz!Invalid refresh token argument: "z]". Refresh token argument must be a file path, or a dict containing the parsed file contents.r4   zNInvalid refresh token configuration. JSON must contain a "type" field set to "r5   )r$   r%   r9   r:   r;   r<   r=   r>   r?   r@   rA   r   r   from_authorized_user_inforC   r&   )r   refresh_tokenrE   rF   r'   s       r   r%   zRefreshToken.__init__   s]     	'' 	Rmg666 1) Ii00	1 1 1 1 1 1 1 1 1 1 1 1 1 1 1t,, 	R%IIQM Q Q QR R R ==  D$999B(,(=B B BC C C )4NNyZabbs   A##A'*A'c                     | j         j        S r"   )r&   	client_idr   s    r   rc   zRefreshToken.client_id   s    !++r   c                     | j         j        S r"   )r&   client_secretr   s    r   re   zRefreshToken.client_secret       !//r   c                     | j         j        S r"   )r&   ra   r   s    r   ra   zRefreshToken.refresh_token   rf   r   c                     | j         S rO   r)   r   s    r   r   zRefreshToken.get_credential   r*   r   )r   r   r   r   rA   r%   rP   rc   re   ra   r   r,   r-   s   @r   r]   r]      s        BB(c c c c cB , , X, 0 0 X0 0 0 X0" " " " " " "r   r]   c                 R    	 t          j        |            dS # t          $ r Y dS w xY w)NTF)pathlibPath	TypeError)paths    r   r9   r9      s>    Tt   uus    
&&)r   collectionsr;   rj   google.authrY   google.auth.credentialsr   r+   google.auth.transportr   google.oauth2r   r   Requestr   rC   
namedtupler   r   r   r/   rR   r]   r9   r   r   r   <module>ru      s   # "           H H H H H H * * * * * * % % % % % % ) ) ) ) ) ) 8   )+():^X<VWW" " " " " " " """ " " " "4 " " ":" :" :" :" :"$ :" :" :"z%W %W %W %W %W %W %W %WN7" 7" 7" 7" 7"4 7" 7" 7"t    r   