
    ]h!                         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y)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y)Basez>Provides OAuth2 access tokens for accessing Firebase services.c                     | j                         }|j                  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/Kila-kolis-project/venv/lib/python3.12/site-packages/firebase_admin/credentials.pyget_access_tokenzBase.get_access_token0   s9     ))+H%{00+2D2D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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                 8    t         t        |           || _        y N)superr   __init___g_credential)r   r    	__class__s     r   r$   z_ExternalCredentials.__init__A   s    "D24'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   >   s    V(#8 ("r   r   c                   \     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                 6   t         t        |           t        |      r*t	        |      5 }t        j                  |      }ddd       n-t        |t              r|}nt        dj                  |            j                  d      | j                  k7  r$t        dj                  | j                              	 t        j                  j                  |t               | _        y# 1 sw Y   wxY w# t        $ r}t        dj                  |            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}")r#   r.   r$   _is_file_pathopenjsonload
isinstancedict
ValueErrorformatget_CREDENTIAL_TYPEr   r   from_service_account_info_scopesr%   )r   cert	json_file	json_dataerrorr&   s        r   r$   zCertificate.__init__Q   s     	k4)+dy IIi0	 d#IAAGO O == D$9$99 ::@&AVAV:WY Y	?!0!<!<!V!V' "W "+D   	? 006u? ?	?s#   C$9*C0 $C-0	D9DDc                 .    | j                   j                  S r"   )r%   
project_idr   s    r   rD   zCertificate.project_idt   s    !!,,,r   c                 .    | j                   j                  S r"   )r%   signerr   s    r   rF   zCertificate.signerx   s    !!(((r   c                 .    | j                   j                  S r"   )r%   service_account_emailr   s    r   rH   z!Certificate.service_account_email|   s    !!7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   r<   r$   propertyrD   rF   rH   r   r+   r,   s   @r   r.   r.   L   sS    C(!?F - - ) ) 8 8"r   r.   c                   >     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                 8    t         t        |           d| _        y)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#   rM   r$   r%   )r   r&   s    r   r$   zApplicationDefault.__init__   s     	 $02!r   c                 :    | j                          | 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                 :    | j                          | 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.)rP   _project_idr   s    r   rD   zApplicationDefault.project_id   s     	r   c                     | j                   s2t        j                  j                  t              \  | _         | _        y y )Nr1   )r%   googleauthdefaultr>   rR   r   s    r   rP   z#ApplicationDefault._load_credential   s2    !!39;;3F3Fg3F3V0D 0 "r   )
r   r   r   r   r$   r   rK   rD   rP   r+   r,   s   @r   rM   rM      s*    2"	" 	  	 Wr   rM   c                   \     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-t        |t              r|}nt        dj                  |            j                  d      | j                  k7  r$t        dj                  | j                              t        j                  j                  |t               | _        y# 1 sw Y   uxY w)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.r0   zSInvalid refresh token configuration. JSON must contain a "type" field set to "{0}".)r#   rX   r$   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   r   from_authorized_user_infor>   r%   )r   refresh_tokenr@   rA   r&   s       r   r$   zRefreshToken.__init__   s      	lD*,'m$	 IIi0	 %$t,%IGGMvmG\^ ^ == D$9$99 ::@&AVAV:WY Y(44NNyZab %$s   C""C+c                 .    | j                   j                  S r"   )r%   	client_idr   s    r   r^   zRefreshToken.client_id   s    !!+++r   c                 .    | j                   j                  S r"   )r%   client_secretr   s    r   r`   zRefreshToken.client_secret       !!///r   c                 .    | j                   j                  S r"   )r%   r\   r   s    r   r\   zRefreshToken.refresh_token   ra   r   c                     | j                   S rJ   r(   r   s    r   r   zRefreshToken.get_credential   r)   r   )r   r   r   r   r<   r$   rK   r^   r`   r\   r   r+   r,   s   @r   rX   rX      sT    B(c@ , , 0 0 0 0"r   rX   c                 N    	 t        j                  |        y# t        $ r Y yw xY w)NTF)pathlibPath	TypeError)paths    r   r3   r3      s(    T s    	$$)r   collectionsr5   re   google.authrT   google.auth.credentialsr   r*   google.auth.transportr   google.oauth2r   r   Requestr   r>   
namedtupler   r   r   r.   rM   rX   r3   r   r   r   <module>rp      s    #     H * % ) 8 )+(():^X<VW" """4 "9"$ 9"x%W %WN6"4 6"rr   