
    f                        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
  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d ZdS )zFirebase credentials module.    N)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     T/var/www/html/Alfredo/env/lib/python3.11/site-packages/firebase_admin/credentials.pyget_access_tokenzBase.get_access_token/   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_credential9   s    !!r   N)__name__
__module____qualname____doc__r   r    r   r   r
   r
   ,   s;        HHF F F" " " " "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                    t          t          |                                            t          |          r<t	          |          5 }t          j        |          }ddd           n# 1 swxY w Y   n:t          |t                    r|}n"t          d
                    |                    |                    d          | j        k    r't          d
                    | j                            	 t          j                            |t                     | _        dS # t          $ r'}t          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.
        Nz}Invalid certificate argument: "{0}". Certificate argument must be a file path, or a dict containing the parsed file contents.typezZInvalid service account certificate. Certificate must contain a "type" field set to "{0}".scopesz?Failed to initialize a certificate credential. Caused by: "{0}")superr   __init___is_file_pathopenjsonload
isinstancedict
ValueErrorformatget_CREDENTIAL_TYPEr   Credentialsfrom_service_account_info_scopes_g_credential)r   cert	json_file	json_dataerror	__class__s        r   r$   zCertificate.__init__C   s    	k4  ))+++ 	Od 1y Ii00	1 1 1 1 1 1 1 1 1 1 1 1 1 1 1d## 	OIIAAGO O O ==  D$999 ::@&AV:W:WY Y Y	?!0!<!V!V' "W "+ "+D 	? 	? 	? 006u? ? ?	?s*   A((A,/A,4+D! !
E+"EEc                     | j         j        S N)r2   
project_idr   s    r   r:   zCertificate.project_idf   s    !,,r   c                     | j         j        S r9   )r2   signerr   s    r   r<   zCertificate.signerj   s    !((r   c                     | j         j        S r9   )r2   service_account_emailr   s    r   r>   z!Certificate.service_account_emailn   s    !77r   c                     | j         S zReturns the underlying Google credential.

        Returns:
          google.auth.credentials.Credentials: A Google Auth credential instance.r2   r   s    r   r   zCertificate.get_credentialr       
 !!r   )r   r   r   r   r.   r$   propertyr:   r<   r>   r   __classcell__r7   s   @r   r   r   >   s        CC(!? !? !? !? !?F - - 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                 d    t          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.
        N)r#   rG   r$   r2   )r   r7   s    r   r$   zApplicationDefault.__init__}   s0     	 $''00222!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_credentialr2   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.)rJ   _project_idr   s    r   r:   zApplicationDefault.project_id   s     	r   c                 |    | j         s4t          j                            t                    \  | _         | _        d S d S )Nr!   )r2   googleauthdefaultr1   rL   r   s    r   rJ   z#ApplicationDefault._load_credential   sC    ! 	W39;3F3Fg3F3V3V0D 0 0 0	W 	Wr   )
r   r   r   r   r$   r   rC   r:   rJ   rD   rE   s   @r   rG   rG   z   s~        22" " " " "	" 	" 	" 	  	  X	 W W W W W W Wr   rG   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          |                                            t          |          r<t	          |          5 }t          j        |          }ddd           n# 1 swxY w Y   n:t          |t                    r|}n"t          d
                    |                    |                    d          | j        k    r't          d
                    | j                            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.
        NzInvalid refresh token argument: "{0}". Refresh token argument must be a file path, or a dict containing the parsed file contents.r    zSInvalid refresh token configuration. JSON must contain a "type" field set to "{0}".)r#   rR   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r/   from_authorized_user_infor1   r2   )r   refresh_tokenr4   r5   r7   s       r   r$   zRefreshToken.__init__   sL     	lD!!**,,,'' 	^m$$ 1	 Ii00	1 1 1 1 1 1 1 1 1 1 1 1 1 1 1t,, 	^%IIGGMvmG\G\^ ^ ^ ==  D$999 ::@&AV:W:WY Y Y(4NNyZabbs   A((A,/A,c                     | j         j        S r9   )r2   	client_idr   s    r   rX   zRefreshToken.client_id   s    !++r   c                     | j         j        S r9   )r2   client_secretr   s    r   rZ   zRefreshToken.client_secret       !//r   c                     | j         j        S r9   )r2   rV   r   s    r   rV   zRefreshToken.refresh_token   r[   r   c                     | j         S r@   rA   r   s    r   r   zRefreshToken.get_credential   rB   r   )r   r   r   r   r.   r$   rC   rX   rZ   rV   r   rD   rE   s   @r   rR   rR      s        BB(c c c c c@ , , X, 0 0 X0 0 0 X0" " " " " " "r   rR   c                 R    	 t          j        |            dS # t          $ r Y dS w xY w)NTF)pathlibPath	TypeError)paths    r   r%   r%      s>    Tt   uus    
&&)r   collectionsr'   r_   google.authrN   google.auth.transportr   google.oauth2r   r   Requestr   r1   
namedtupler   r
   r   rG   rR   r%   r   r   r   <module>ri      s{   # "           * * * * * * % % % % % % ) ) ) ) ) ) 8   )+():^X<VWW" " " " " " " "$9" 9" 9" 9" 9"$ 9" 9" 9"x%W %W %W %W %W %W %W %WN6" 6" 6" 6" 6"4 6" 6" 6"r    r   