o
    ˷eC                     @   sr   d Z ddlZddlZddlmZ dd ZG dd dZG dd	 d	ZG d
d dZG dd dZ	G dd dZ
dS )z Firebase user import sub module.    N)_auth_utilsc                 C   s   t |  S N)base64urlsafe_b64encodedecode)bytes_value r   R/var/www/ideatree/venv/lib/python3.10/site-packages/firebase_admin/_user_import.py
b64_encode   s   r
   c                   @   s   e Zd ZdZdddZedd Zejdd Zedd	 Zejd
d	 Zedd Z	e	jdd Z	edd Z
e
jdd Z
edd Zejdd Zdd ZdS )UserProvideraD  Represents a user identity provider that can be associated with a Firebase user.

    One or more providers can be specified in an ``ImportUserRecord`` when importing users via
    ``auth.import_users()``.

    Args:
        uid: User's unique ID assigned by the identity provider.
        provider_id: ID of the identity provider. This can be a short domain name or the identifier
            of an OpenID identity provider.
        email: User's email address (optional).
        display_name: User's display name (optional).
        photo_url: User's photo URL (optional).
    Nc                 C   s"   || _ || _|| _|| _|| _d S r   )uidprovider_idemaildisplay_name	photo_url)selfr   r   r   r   r   r   r   r	   __init__*   s
   
zUserProvider.__init__c                 C      | j S r   _uidr   r   r   r	   r   1      zUserProvider.uidc                 C      t j|dd| _d S NTrequiredr   validate_uidr   r   r   r   r   r	   r   5      c                 C   r   r   )_provider_idr   r   r   r	   r   9   r   zUserProvider.provider_idc                 C   r   r   )r   validate_provider_idr    )r   r   r   r   r	   r   =   r   c                 C   r   r   _emailr   r   r   r	   r   A   r   zUserProvider.emailc                 C      t || _d S r   r   validate_emailr#   r   r   r   r   r	   r   E      c                 C   r   r   _display_namer   r   r   r	   r   I   r   zUserProvider.display_namec                 C   r$   r   r   validate_display_namer*   r   r   r   r   r	   r   M   r(   c                 C   r   r   
_photo_urlr   r   r   r	   r   Q   r   zUserProvider.photo_urlc                 C   r$   r   r   validate_photo_urlr/   r   r   r   r   r	   r   U   r(   c                 C   s,   | j | j| j| j| jd}dd | D S )N)rawId
providerIddisplayNamer   photoUrlc                 S      i | ]\}}|d ur||qS r   r   .0kvr   r   r	   
<dictcomp>a       z(UserProvider.to_dict.<locals>.<dictcomp>)r   r   r   r   r   itemsr   payloadr   r   r	   to_dictY   s   zUserProvider.to_dict)NNN)__name__
__module____qualname____doc__r   propertyr   setterr   r   r   r   rA   r   r   r   r	   r      s0    










r   c                   @   s,  e Zd ZdZ			d%ddZedd Zejdd Zedd	 Zejd
d	 Zedd Z	e	jdd Z	edd Z
e
jdd Z
edd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zed d! Zejd"d! Zd#d$ ZdS )&ImportUserRecordar  Represents a user account to be imported to Firebase Auth.

    Must specify the ``uid`` field at a minimum. A sequence of ``ImportUserRecord`` objects can be
    passed to the ``auth.import_users()`` function, in order to import those users into Firebase
    Auth in bulk. If the ``password_hash`` is set on a user, a hash configuration must be
    specified when calling ``import_users()``.

    Args:
        uid: User's unique ID. Must be a non-empty string not longer than 128 characters.
        email: User's email address (optional).
        email_verified: A boolean indicating whether the user's email has been verified (optional).
        display_name: User's display name (optional).
        phone_number: User's phone number (optional).
        photo_url: User's photo URL (optional).
        disabled: A boolean indicating whether this user account has been disabled (optional).
        user_metadata: An ``auth.UserMetadata`` instance with additional user metadata (optional).
        provider_data: A list of ``auth.UserProvider`` instances (optional).
        custom_claims: A ``dict`` of custom claims to be set on the user account (optional).
        password_hash: User's password hash as a ``bytes`` sequence (optional).
        password_salt: User's password salt as a ``bytes`` sequence (optional).

    Raises:
        ValueError: If provided arguments are invalid.
    Nc                 C   sL   || _ || _|| _|| _|| _|| _|| _|| _|| _|| _	|	| _
|
| _d S r   )r   r   r   phone_numberr   password_hashpassword_saltemail_verifieddisableduser_metadataprovider_datacustom_claims)r   r   r   rL   r   rI   r   rM   rN   rO   rP   rJ   rK   r   r   r	   r   ~   s   
zImportUserRecord.__init__c                 C   r   r   r   r   r   r   r	   r      r   zImportUserRecord.uidc                 C   r   r   r   r   r   r   r	   r      r   c                 C   r   r   r"   r   r   r   r	   r      r   zImportUserRecord.emailc                 C   r$   r   r%   r'   r   r   r	   r      r(   c                 C   r   r   r)   r   r   r   r	   r      r   zImportUserRecord.display_namec                 C   r$   r   r+   r-   r   r   r	   r      r(   c                 C   r   r   )_phone_numberr   r   r   r	   rI      r   zImportUserRecord.phone_numberc                 C   r$   r   )r   validate_phonerQ   )r   rI   r   r   r	   rI      r(   c                 C   r   r   r.   r   r   r   r	   r      r   zImportUserRecord.photo_urlc                 C   r$   r   r0   r2   r   r   r	   r      r(   c                 C   r   r   )_password_hashr   r   r   r	   rJ      r   zImportUserRecord.password_hashc                 C      t |d| _d S )NrJ   )r   validate_bytesrS   )r   rJ   r   r   r	   rJ         c                 C   r   r   )_password_saltr   r   r   r	   rK      r   zImportUserRecord.password_saltc                 C   rT   )NrK   )r   rU   rW   )r   rK   r   r   r	   rK      rV   c                 C   r   r   )_user_metadatar   r   r   r	   rN      r   zImportUserRecord.user_metadatac                 C   sJ   |d ur|j nd }|d ur|jnd }t|d| _t|d| _|| _d S )Ncreation_timestamplast_sign_in_timestamp)rY   rZ   r   validate_timestamp_created_at_last_login_atrX   )r   rN   
created_atlast_login_atr   r   r	   rN      s   
c                 C   r   r   )_provider_datar   r   r   r	   rO      r   zImportUserRecord.provider_datac                 C   sH   |d urzt dd |D rtdW n ty   tdw || _d S )Nc                 S   s   g | ]}t |t qS r   )
isinstancer   r9   pr   r   r	   
<listcomp>   s    z2ImportUserRecord.provider_data.<locals>.<listcomp>z0One or more provider data instances are invalid.zprovider_data must be iterable.)any
ValueError	TypeErrorr`   )r   rO   r   r   r	   rO      s   
c                 C   r   r   )_custom_claimsr   r   r   r	   rP      r   zImportUserRecord.custom_claimsc                 C   s.   t |tr
t|n|}t|| _|| _d S r   )ra   dictjsondumpsr   validate_custom_claims_custom_claims_strrh   )r   rP   json_claimsr   r   r	   rP      s   
c                 C   s   | j | j| j| j| j| jdurt| jnd| jdurt| jnd| j| j	| j
| jr.t| jnd| jr7t| jndd}| jrHdd | jD |d< dd | D S )zAReturns a dict representation of the user. For internal use only.N)localIdr   r5   phoneNumberr6   emailVerifiedrM   customAttributes	createdAtlastLoginAtpasswordHashsaltc                 S   s   g | ]}|  qS r   )rA   rb   r   r   r	   rd          z,ImportUserRecord.to_dict.<locals>.<listcomp>providerUserInfoc                 S   r7   r   r   r8   r   r   r	   r<      r=   z,ImportUserRecord.to_dict.<locals>.<dictcomp>)r   r   r   rI   r   rL   boolrM   rm   r\   r]   rJ   r
   rK   rO   r>   r?   r   r   r	   rA      s$   

zImportUserRecord.to_dict)NNNNNNNNNNN)rB   rC   rD   rE   r   rF   r   rG   r   r   rI   r   rJ   rK   rN   rO   rP   rA   r   r   r   r	   rH   d   s^    


















	

rH   c                   @   s   e Zd ZdZd#ddZdd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zed#ddZedd  Zed!d" ZdS )$UserImportHasha  Represents a hash algorithm used to hash user passwords.

    An instance of this class must be specified when importing users with passwords via the
    ``auth.import_users()`` API. Use one of the provided class methods to obtain new
    instances when required. Refer to `documentation`_ for more details.

    .. _documentation: https://firebase.google.com/docs/auth/admin/import-users
    Nc                 C   s   || _ || _d S r   )_name_data)r   namedatar   r   r	   r     s   
zUserImportHash.__init__c                 C   s    d| j i}| jr|| j |S )NhashAlgorithm)r{   r|   updater?   r   r   r	   rA     s   
zUserImportHash.to_dictc                 C   s"   dt tj|dddi}t||S )N	signerKeykeyTr   )r
   r   rU   rz   )clsr}   r   r~   r   r   r	   _hmac  s   
zUserImportHash._hmacc                 C      |  d|S )zCreates a new HMAC SHA512 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        HMAC_SHA512r   r   r   r   r   r	   hmac_sha512     
zUserImportHash.hmac_sha512c                 C   r   )zCreates a new HMAC SHA256 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        HMAC_SHA256r   r   r   r   r	   hmac_sha256)  r   zUserImportHash.hmac_sha256c                 C   r   )zCreates a new HMAC SHA1 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        	HMAC_SHA1r   r   r   r   r	   	hmac_sha15  r   zUserImportHash.hmac_sha1c                 C   r   )zCreates a new HMAC MD5 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        HMAC_MD5r   r   r   r   r	   hmac_md5A  r   zUserImportHash.hmac_md5c              	   C      t ddt|dddiS )zCreates a new MD5 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        MD5roundsr       rz   r   validate_intr   r   r   r   r	   md5M     
zUserImportHash.md5c              	   C   r   )zCreates a new SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        SHA1r      r   r   r   r   r   r	   sha1[  r   zUserImportHash.sha1c              	   C   r   )zCreates a new SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        SHA256r   r   r   r   r   r   r   r	   sha256i  r   zUserImportHash.sha256c              	   C   r   )zCreates a new SHA512 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 1 and 8192.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        SHA512r   r   r   r   r   r   r   r	   sha512w  r   zUserImportHash.sha512c              	   C   r   )zCreates a new PBKDF SHA1 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        
PBKDF_SHA1r   r    r   r   r   r   r	   
pbkdf_sha1  r   zUserImportHash.pbkdf_sha1c              	   C   r   )zCreates a new PBKDF2 SHA256 algorithm instance.

        Args:
            rounds: Number of rounds. Must be an integer between 0 and 120000.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        PBKDF2_SHA256r   r   r   r   r   r   r   r	   pbkdf2_sha256  r   zUserImportHash.pbkdf2_sha256c                 C   sV   t tj|dddt|dddt|dddd	}|r&t t|d
|d< td|S )a$  Creates a new Scrypt algorithm instance.

        This is the modified Scrypt algorithm used by Firebase Auth. See ``standard_scrypt()``
        function for the standard Scrypt algorith,

        Args:
            key: Signer key as a byte sequence.
            rounds: Number of rounds. Must be an integer between 1 and 8.
            memory_cost: Memory cost as an integer between 1 and 14.
            salt_separator: Salt separator as a byte sequence (optional).

        Returns:
            UserImportHash: A new ``UserImportHash``.
        r   Tr   r   r      memory_cost   )r   r   
memoryCostsalt_separatorsaltSeparatorSCRYPT)r
   r   rU   r   rz   )r   r   r   r   r   r~   r   r   r	   scrypt  s   

zUserImportHash.scryptc                 C   s   t dS )zyCreates a new Bcrypt algorithm instance.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        BCRYPT)rz   )r   r   r   r	   bcrypt  s   zUserImportHash.bcryptc                 C   sH   t j|dddt j|dddt j|dddt j|dddd}td|S )	a  Creates a new standard Scrypt algorithm instance.

        Args:
            memory_cost: Memory cost as a non-negaive integer.
            parallelization: Parallelization as a non-negative integer.
            block_size: Block size as a non-negative integer.
            derived_key_length: Derived key length as a non-negative integer.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        r   r   )lowparallelization
block_sizederived_key_length)r   r   	blockSizedkLenSTANDARD_SCRYPT)r   r   rz   )r   r   r   r   r   r~   r   r   r	   standard_scrypt  s   
zUserImportHash.standard_scryptr   )rB   rC   rD   rE   r   rA   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   rz     s@    
	











rz   c                   @   s0   e Zd ZdZdd Zedd Zedd ZdS )		ErrorInfozRepresents an error encountered while performing a batch operation such
    as importing users or deleting multiple user accounts.
    c                 C   s   |d | _ |d | _d S )Nindexmessage)_index_reason)r   errorr   r   r	   r     s   
zErrorInfo.__init__c                 C   r   r   )r   r   r   r   r	   r     r   zErrorInfo.indexc                 C   r   r   )r   r   r   r   r	   reason  r   zErrorInfo.reasonN)rB   rC   rD   rE   r   rF   r   r   r   r   r   r	   r     s    
r   c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )UserImportResultzrRepresents the result of a bulk user import operation.

    See ``auth.import_users()`` API for more details.
    c                 C   s8   | dg }|t| | _t|| _dd |D | _d S )Nr   c                 S   s   g | ]}t |qS r   )r   )r9   errr   r   r	   rd     rw   z-UserImportResult.__init__.<locals>.<listcomp>)getlen_success_count_failure_count_errors)r   resulttotalerrorsr   r   r	   r     s   
zUserImportResult.__init__c                 C   r   )z2Returns the number of users successfully imported.)r   r   r   r   r	   success_count     zUserImportResult.success_countc                 C   r   )z7Returns the number of users that failed to be imported.)r   r   r   r   r	   failure_count   r   zUserImportResult.failure_countc                 C   r   )zQReturns a list of ``auth.ErrorInfo`` instances describing the errors encountered.)r   r   r   r   r	   r     r   zUserImportResult.errorsN)	rB   rC   rD   rE   r   rF   r   r   r   r   r   r   r	   r     s    

r   )rE   r   rj   firebase_adminr   r
   r   rH   rz   r   r   r   r   r   r	   <module>   s   I  Y