
    ѮhD                         d Z ddlZddlZddlmZ d Z G d d      Z G d d      Z G d	 d
      Z G d d      Z	 G d d      Z
y)z Firebase user import sub module.    N)_auth_utilsc                 H    t        j                  |       j                         S N)base64urlsafe_b64encodedecode)bytes_values    m/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/firebase_admin/_user_import.py
b64_encoder      s    ##K07799    c                   "   e Zd ZdZddZed        Zej                  d        Zed        Zej                  d        Zed        Z	e	j                  d	        Z	ed
        Z
e
j                  d        Z
ed        Zej                  d        Zd Zy)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                 J    || _         || _        || _        || _        || _        y r   )uidprovider_idemaildisplay_name	photo_url)selfr   r   r   r   r   s         r
   __init__zUserProvider.__init__*   s'    &
("r   c                     | j                   S r   _uidr   s    r
   r   zUserProvider.uid1       yyr   c                 <    t        j                  |d      | _        y NTrequiredr   validate_uidr   r   r   s     r
   r   zUserProvider.uid5       ,,S4@	r   c                     | j                   S r   )_provider_idr   s    r
   r   zUserProvider.provider_id9   s       r   c                 <    t        j                  |d      | _        y r   )r   validate_provider_idr%   )r   r   s     r
   r   zUserProvider.provider_id=   s    '<<[SWXr   c                     | j                   S r   _emailr   s    r
   r   zUserProvider.emailA       {{r   c                 8    t        j                  |      | _        y r   r   validate_emailr*   r   r   s     r
   r   zUserProvider.emailE       !007r   c                     | j                   S r   _display_namer   s    r
   r   zUserProvider.display_nameI       !!!r   c                 8    t        j                  |      | _        y r   r   validate_display_namer3   r   r   s     r
   r   zUserProvider.display_nameM       (>>|Lr   c                     | j                   S r   
_photo_urlr   s    r
   r   zUserProvider.photo_urlQ       r   c                 8    t        j                  |      | _        y r   r   validate_photo_urlr<   r   r   s     r
   r   zUserProvider.photo_urlU       %88Cr   c                     | j                   | j                  | j                  | j                  | j                  d}|j                         D ci c]  \  }}|	|| c}}S c c}}w )N)rawId
providerIddisplayNamer   photoUrl)r   r   r   r   r   items)r   payloadkvs       r
   to_dictzUserProvider.to_dictY   sX    XX**,,ZZ
 ")BAAM1BBBs   
A"A")NNN)__name__
__module____qualname____doc__r   propertyr   setterr   r   r   r   rL    r   r
   r   r      s    #   	ZZA A ! ! Y Y   \\8 8 " " M M   D DCr   r   c                   ,   e Zd ZdZ	 	 	 ddZed        Zej                  d        Zed        Zej                  d        Zed        Z	e	j                  d	        Z	ed
        Z
e
j                  d        Z
ed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zd Zy)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                     || _         || _        || _        || _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        y r   )r   r   r   phone_numberr   password_hashpassword_saltemail_verifieddisableduser_metadataprovider_datacustom_claims)r   r   r   rZ   r   rW   r   r[   r\   r]   r^   rX   rY   s                r
   r   zImportUserRecord.__init__~   s`     
(("**, ***r   c                     | j                   S r   r   r   s    r
   r   zImportUserRecord.uid   r   r   c                 <    t        j                  |d      | _        y r   r    r"   s     r
   r   zImportUserRecord.uid   r#   r   c                     | j                   S r   r)   r   s    r
   r   zImportUserRecord.email   r+   r   c                 8    t        j                  |      | _        y r   r-   r/   s     r
   r   zImportUserRecord.email   r0   r   c                     | j                   S r   r2   r   s    r
   r   zImportUserRecord.display_name   r4   r   c                 8    t        j                  |      | _        y r   r6   r8   s     r
   r   zImportUserRecord.display_name   r9   r   c                     | j                   S r   )_phone_numberr   s    r
   rW   zImportUserRecord.phone_number   r4   r   c                 8    t        j                  |      | _        y r   )r   validate_phonerf   )r   rW   s     r
   rW   zImportUserRecord.phone_number   s    (77Er   c                     | j                   S r   r;   r   s    r
   r   zImportUserRecord.photo_url   r=   r   c                 8    t        j                  |      | _        y r   r?   rA   s     r
   r   zImportUserRecord.photo_url   rB   r   c                     | j                   S r   )_password_hashr   s    r
   rX   zImportUserRecord.password_hash       """r   c                 :    t        j                  |d      | _        y )NrX   )r   validate_bytesrl   )r   rX   s     r
   rX   zImportUserRecord.password_hash       )88Xr   c                     | j                   S r   )_password_saltr   s    r
   rY   zImportUserRecord.password_salt   rm   r   c                 :    t        j                  |d      | _        y )NrY   )r   ro   rr   )r   rY   s     r
   rY   zImportUserRecord.password_salt   rp   r   c                     | j                   S r   )_user_metadatar   s    r
   r\   zImportUserRecord.user_metadata   rm   r   c                     ||j                   nd }||j                  nd }t        j                  |d      | _        t        j                  |d      | _        || _        y )Ncreation_timestamplast_sign_in_timestamp)rw   rx   r   validate_timestamp_created_at_last_login_atru   )r   r\   
created_atlast_login_ats       r
   r\   zImportUserRecord.user_metadata   s_    9F9R]55X\
@M@Y<<_c&99*FZ[)<<35+r   c                     | j                   S r   )_provider_datar   s    r
   r]   zImportUserRecord.provider_data   rm   r   c                     |'	 t        d |D              rt        d      	 || _        y || _        y # t        $ r}t        d      |d }~ww xY w)Nc              3   >   K   | ]  }t        |t                 y wr   )
isinstancer   ).0ps     r
   	<genexpr>z1ImportUserRecord.provider_data.<locals>.<genexpr>   s     N1:a66Ns   z0One or more provider data instances are invalid.zprovider_data must be iterable.)any
ValueError	TypeErrorr   )r   r]   errs      r
   r]   zImportUserRecord.provider_data   sa    $MNNN$%WXX O ,m  M !BCLMs   2 	AAAc                     | j                   S r   )_custom_claimsr   s    r
   r^   zImportUserRecord.custom_claims   rm   r   c                     t        |t              rt        j                  |      n|}t	        j
                  |      | _        || _        y r   )r   dictjsondumpsr   validate_custom_claims_custom_claims_strr   )r   r^   json_claimss      r
   r^   zImportUserRecord.custom_claims   s=    3=44!djj/&3 	"-"D"D["Q+r   c                    | j                   | j                  | j                  | j                  | j                  | j
                  t        | j
                        nd| j                  t        | j                        nd| j                  | j                  | j                  | j                  rt        | j                        nd| j                  rt        | j                        ndd}| j                  r+| j                  D cg c]  }|j                          c}|d<   |j!                         D ci c]  \  }}|	|| c}}S c c}w c c}}w )zAReturns a dict representation of the user. For internal use only.N)localIdr   rF   phoneNumberrG   emailVerifiedr[   customAttributes	createdAtlastLoginAtpasswordHashsaltproviderUserInfo)r   r   r   rW   r   rZ   boolr[   r   rz   r{   rX   r   rY   r]   rL   rH   )r   rI   r   rJ   rK   s        r
   rL   zImportUserRecord.to_dict   s    xxZZ,,,,!%!4!4!@ #4#6#67FJ/3}}/HT]]+d $ 7 7))..>B>P>PJt'9'9:VZ6:6H6HJt112d
 @D@R@R*S1199;*SG&'!(BAAM1BB +TBs   >E.
E9E)NNNNNNNNNNN)rM   rN   rO   rP   r   rQ   r   rR   r   r   rW   r   rX   rY   r\   r]   r^   rL   rS   r   r
   rU   rU   d   s   2 ^bRVGK+    	ZZA A   \\8 8 " " M M " " F F   D D # # Y Y # # Y Y # # , , # # , , # # , ,Cr   rU   c                       e Zd ZdZddZd Zed        Zed        Zed        Z	ed        Z
ed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zedd       Zed        Zed        Zy)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                      || _         || _        y r   )_name_data)r   namedatas      r
   r   zUserImportHash.__init__  s    

r   c                 p    d| j                   i}| j                  r|j                  | j                         |S )NhashAlgorithm)r   r   update)r   rI   s     r
   rL   zUserImportHash.to_dict  s,    "DJJ/::NN4::&r   c                 `    dt        t        j                  |dd            i}t        ||      S )N	signerKeykeyTr   )r   r   ro   r   )clsr   r   r   s       r
   _hmaczUserImportHash._hmac  s4     K$>$>sETX$YZ
 dD))r   c                 &    | j                  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   s     r
   hmac_sha512zUserImportHash.hmac_sha512       yy,,r   c                 &    | j                  d|      S )zCreates a new HMAC SHA256 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        HMAC_SHA256r   r   s     r
   hmac_sha256zUserImportHash.hmac_sha256)  r   r   c                 &    | j                  d|      S )zCreates a new HMAC SHA1 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        	HMAC_SHA1r   r   s     r
   	hmac_sha1zUserImportHash.hmac_sha15  s     yyc**r   c                 &    | j                  d|      S )zCreates a new HMAC MD5 algorithm instance.

        Args:
            key: Signer key as a byte sequence.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        HMAC_MD5r   r   s     r
   hmac_md5zUserImportHash.hmac_md5A  s     yyS))r   c           
      J    t        ddt        j                  |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       r   r   validate_intr   r   s     r
   md5zUserImportHash.md5M  s/     {//!TJKM 	Mr   c           
      J    t        ddt        j                  |ddd      i      S )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   s     r
   sha1zUserImportHash.sha1[  s/     {//!TJKM 	Mr   c           
      J    t        ddt        j                  |ddd      i      S )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   s     r
   sha256zUserImportHash.sha256i  /     {//!TJKM 	Mr   c           
      J    t        ddt        j                  |ddd      i      S )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   s     r
   sha512zUserImportHash.sha512w  r   r   c           
      J    t        ddt        j                  |ddd      i      S )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   s     r
   
pbkdf_sha1zUserImportHash.pbkdf_sha1  s/     {//!VLMO 	Or   c           
      J    t        ddt        j                  |ddd      i      S )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   s     r
   pbkdf2_sha256zUserImportHash.pbkdf2_sha256  s/     {//!VLMO 	Or   c                    t        t        j                  |dd            t        j                  |ddd      t        j                  |ddd      d	}|r"t        t        j                  |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   ro   r   r   )r   r   r   r   r   r   s         r
   scryptzUserImportHash.scrypt  s    " $K$>$>sETX$YZ!..vxAF%22;qRTU

 $.{/I/I 002 %3D!h--r   c                     t        d      S )zyCreates a new Bcrypt algorithm instance.

        Returns:
            UserImportHash: A new ``UserImportHash``.
        BCRYPT)r   )r   s    r
   bcryptzUserImportHash.bcrypt  s     h''r   c                     t        j                  |dd      t        j                  |dd      t        j                  |dd      t        j                  |dd      d}t        d|      S )	a  Creates a new standard Scrypt algorithm instance.

        Args:
            memory_cost: CPU Memory cost as a non-negative 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)
cpuMemCostr   	blockSizedkLenSTANDARD_SCRYPT)r   r   r   )r   r   r   r   r   r   s         r
   standard_scryptzUserImportHash.standard_scrypt  sj     &22;STU*77IZ`ab$11*lPQR --.@BV\]^	
 /66r   r   )rM   rN   rO   rP   r   rL   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   rS   r   r
   r   r     s5    * * 	- 	- 	- 	- 	+ 	+ 	* 	* M M M M M M M M O O O O . .2 ( ( 7 7r   r   c                   6    e Zd ZdZd Zed        Zed        Zy)	ErrorInfozRepresents an error encountered while performing a batch operation such
    as importing users or deleting multiple user accounts.
    c                 ,    |d   | _         |d   | _        y )Nindexmessage)_index_reason)r   errors     r
   r   zErrorInfo.__init__  s    GnY'r   c                     | j                   S r   )r   r   s    r
   r   zErrorInfo.index  r+   r   c                     | j                   S r   )r   r   s    r
   reasonzErrorInfo.reason  s    ||r   N)rM   rN   rO   rP   r   rQ   r   r   rS   r   r
   r   r     s4    (    r   r   c                   F    e Zd ZdZd Zed        Zed        Zed        Zy)UserImportResultzrRepresents the result of a bulk user import operation.

    See ``auth.import_users()`` API for more details.
    c                     |j                  dg       }|t        |      z
  | _        t        |      | _        |D cg c]  }t	        |       c}| _        y c c}w )Nr   )getlen_success_count_failure_countr   _errors)r   resulttotalerrorsr   s        r
   r   zUserImportResult.__init__  sH    GR(#c&k1!&k2893	#99s   Ac                     | j                   S )z2Returns the number of users successfully imported.)r   r   s    r
   success_countzUserImportResult.success_count       """r   c                     | j                   S )z7Returns the number of users that failed to be imported.)r   r   s    r
   failure_countzUserImportResult.failure_count   r  r   c                     | j                   S )zQReturns a list of ``auth.ErrorInfo`` instances describing the errors encountered.)r   r   s    r
   r  zUserImportResult.errors  s     ||r   N)	rM   rN   rO   rP   r   rQ   r  r  r  rS   r   r
   r   r     sH    
: # # # #  r   r   )rP   r   r   firebase_adminr   r   r   rU   r   r   r   rS   r   r
   <module>r
     sW    '   &:FC FCR[C [C|U7 U7p * r   