
    (phD                        S r SSKrSSKJr  SSKrSSKJr  SSKrSSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  S
rS
r\R"                  " S5      r " S S5      r\" S5      r " S S5      r " S S5      r " S S\5      r " S S\5      r " S S5      r " S S5      r " S S5      r " S S5      r " S S \5      r " S! S"5      rS# r " S$ S%5      r  " S& S'\	RB                  5      r"g)(z$Firebase user management sub module.    N)defaultdict)parse)_auth_utils)_rfc3339)_user_identifier)_user_import)	ErrorInfo  s   REDACTEDc                       \ rS rSrS rSrg)Sentinel$   c                     Xl         g Ndescription)selfr   s     K/var/www/html/venv/lib/python3.13/site-packages/firebase_admin/_user_mgt.py__init__Sentinel.__init__&   s    &    r   N)__name__
__module____qualname____firstlineno__r   __static_attributes__ r   r   r   r   $   s    'r   r   z5Value used to delete an attribute from a user profilec                   V    \ rS rSrSr  S	S jr\S 5       r\S 5       r\S 5       r	Sr
g)
UserMetadata-   z<Contains additional metadata associated with a user account.Nc                     [         R                  " US5      U l        [         R                  " US5      U l        [         R                  " US5      U l        g )Ncreation_timestamplast_sign_in_timestamplast_refresh_timestamp)r   validate_timestamp_creation_timestamp_last_sign_in_timestamp_last_refresh_timestamp)r   r!   r"   r#   s       r   r   UserMetadata.__init__0   sM    #.#A#A 4$6 '2'E'E"$<(>$'2'E'E"$<(>$r   c                     U R                   $ )zCreation timestamp in milliseconds since the epoch.

Returns:
  integer: The user creation timestamp in milliseconds since the epoch.
)r%   r   s    r   r!   UserMetadata.creation_timestamp9   s     '''r   c                     U R                   $ )zLast sign in timestamp in milliseconds since the epoch.

Returns:
  integer: The last sign in timestamp in milliseconds since the epoch.
)r&   r*   s    r   r"   #UserMetadata.last_sign_in_timestampB   s     +++r   c                     U R                   $ )zThe time at which the user was last active (ID token refreshed).

Returns:
  integer: Milliseconds since epoch timestamp, or `None` if the user was
  never active.
)r'   r*   s    r   r#   #UserMetadata.last_refresh_timestampK   s     +++r   )r%   r'   r&   )NNN)r   r   r   r   __doc__r   propertyr!   r"   r#   r   r   r   r   r   r   -   sL    FGK(,> ( ( , , , ,r   r   c                   x    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	rg
)UserInfoV   zA collection of standard profile information for a user.

Used to expose profile information returned by an identity provider.
c                     [         e)z!Returns the user ID of this user.NotImplementedErrorr*   s    r   uidUserInfo.uid\   
     "!r   c                     [         e)z&Returns the display name of this user.r6   r*   s    r   display_nameUserInfo.display_namea   r:   r   c                     [         e)z4Returns the email address associated with this user.r6   r*   s    r   emailUserInfo.emailf   r:   r   c                     [         e)z3Returns the phone number associated with this user.r6   r*   s    r   phone_numberUserInfo.phone_numberk   r:   r   c                     [         e)z#Returns the photo URL of this user.r6   r*   s    r   	photo_urlUserInfo.photo_urlp   r:   r   c                     [         e)zReturns the ID of the identity provider.

This can be a short domain name (e.g. google.com), or the identity of an OpenID
identity provider.
r6   r*   s    r   provider_idUserInfo.provider_idu   s
     "!r   r   N)r   r   r   r   r0   r1   r8   r<   r?   rB   rE   rH   r   r   r   r   r3   r3   V   s    
 " " " " " " " " " " " "r   r3   c                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )
UserRecord   z:Contains metadata associated with a Firebase user account.c                    > [         [        U ]  5         [        U[        5      (       d  [        SR                  U5      5      eUR                  S5      (       d  [        S5      eXl        g )N1Invalid data argument: {0}. Must be a dictionary.localId"User ID must not be None or empty.)	superrK   r   
isinstancedict
ValueErrorformatget_datar   data	__class__s     r   r   UserRecord.__init__   sU    j$(*$%%PWWX\]^^xx	""ABB
r   c                 8    U R                   R                  S5      $ )zkReturns the user ID of this user.

Returns:
  string: A user ID string. This value is never None or empty.
rO   rW   rV   r*   s    r   r8   UserRecord.uid   s     zz~~i((r   c                 8    U R                   R                  S5      $ )zZReturns the display name of this user.

Returns:
  string: A display name string or None.
displayNamer]   r*   s    r   r<   UserRecord.display_name        zz~~m,,r   c                 8    U R                   R                  S5      $ )zjReturns the email address associated with this user.

Returns:
  string: An email address string or None.
r?   r]   r*   s    r   r?   UserRecord.email   s     zz~~g&&r   c                 8    U R                   R                  S5      $ )zgReturns the phone number associated with this user.

Returns:
  string: A phone number string or None.
phoneNumberr]   r*   s    r   rB   UserRecord.phone_number   rb   r   c                 8    U R                   R                  S5      $ )zNReturns the photo URL of this user.

Returns:
  string: A URL string or None.
photoUrlr]   r*   s    r   rE   UserRecord.photo_url        zz~~j))r   c                     g)zXReturns the provider ID of this user.

Returns:
  string: A constant provider ID value.
firebaser   r*   s    r   rH   UserRecord.provider_id   s     r   c                 J    [        U R                  R                  S5      5      $ )zReturns whether the email address of this user has been verified.

Returns:
  bool: True if the email has been verified, and False otherwise.
emailVerifiedboolrW   rV   r*   s    r   email_verifiedUserRecord.email_verified   s     DJJNN?344r   c                 J    [        U R                  R                  S5      5      $ )z|Returns whether this user account is disabled.

Returns:
  bool: True if the user account is disabled, and False otherwise.
disabledrq   r*   s    r   rv   UserRecord.disabled   s     DJJNN:.//r   c                 \    U R                   R                  S5      nUb  S[        U5      -  $ g)a  Returns the time, in milliseconds since the epoch, before which tokens are invalid.

Note: this is truncated to 1 second accuracy.

Returns:
    int: Timestamp in milliseconds since the epoch, truncated to the second.
    All tokens issued before that time are considered revoked.

validSincer
   r   )rW   rV   int)r   valid_sinces     r   tokens_valid_after_timestamp'UserRecord.tokens_valid_after_timestamp   s/     jjnn\2"#k***r   c                    ^  U 4S jnSnT R                   R                  SS5      nU(       a"  [        [        R                  " U5      S-  5      n[        U" S5      U" S5      U5      $ )zReturns additional metadata associated with this user.

Returns:
  UserMetadata: A UserMetadata instance. Does not return None.
c                 V   > U TR                   ;   a  [        TR                   U    5      $ g r   )rW   rz   )keyr   s    r   _int_or_none.UserRecord.user_metadata.<locals>._int_or_none   s%    djj 4::c?++r   NlastRefreshAtr
   	createdAtlastLoginAt)rW   rV   rz   r   parse_to_epochr   )r   r   last_refresh_at_millislast_refresh_at_rfc3339s   `   r   user_metadataUserRecord.user_metadata   sf    	 "&"&**..$"G"%()@)@AX)Y\`)`%a"%|M'BDZ\ 	\r   c                 |    U R                   R                  S/ 5      nU Vs/ s H  n[        U5      PM     sn$ s  snf )zReturns a list of UserInfo instances.

Each object represents an identity from an identity provider that is linked to this user.

Returns:
  list: A list of UserInfo objects, which may be empty.
providerUserInfo)rW   rV   ProviderUserInfo)r   	providersentrys      r   provider_dataUserRecord.provider_data   s7     JJNN#5r:	5>?YE 'Y???s   9c                     U R                   R                  S5      nU(       a  [        R                  " U5      nU0 :w  a  U$ g)zfReturns any custom claims set on this user account.

Returns:
  dict: A dictionary of claims or None.
customAttributesN)rW   rV   jsonloads)r   claimsparseds      r   custom_claimsUserRecord.custom_claims   s7      23ZZ'F|r   c                 8    U R                   R                  S5      $ )zTReturns the tenant ID of this user.

Returns:
  string: A tenant ID string or None.
tenantIdr]   r*   s    r   	tenant_idUserRecord.tenant_id  rk   r   rW   )r   r   r   r   r0   r   r1   r8   r<   r?   rB   rE   rH   rs   rv   r|   r   r   r   r   r   __classcell__rZ   s   @r   rK   rK      s   D ) ) - - ' ' - - * *   5 5 0 0   \ \" 	@ 	@   * *r   rK   c                   8    \ rS rSrSr\S 5       r\S 5       rSrg)ExportedUserRecordi  zJContains metadata associated with a user including password hash and salt.c                 R    U R                   R                  S5      nU[        :X  a  gU$ )a  The user's password hash as a base64-encoded string.

If the Firebase Auth hashing algorithm (SCRYPT) was used to create the user account, this
is the base64-encoded password hash of the user. If a different hashing algorithm was
used to create this user, as is typical when migrating from another Auth system, this
is an empty string. If no password is set, or if the service account doesn't have permission
to read the password, then this is ``None``.
passwordHashN)rW   rV   B64_REDACTED)r   password_hashs     r   r    ExportedUserRecord.password_hash  s)     

~6
 L(r   c                 8    U R                   R                  S5      $ )a  The user's password salt as a base64-encoded string.

If the Firebase Auth hashing algorithm (SCRYPT) was used to create the user account, this
is the base64-encoded password salt of the user. If a different hashing algorithm was
used to create this user, as is typical when migrating from another Auth system, this is
an empty string. If no password is set, or if the service account doesn't have permission to
read the password, then this is ``None``.
saltr]   r*   s    r   password_salt ExportedUserRecord.password_salt-  s     zz~~f%%r   r   N)	r   r   r   r   r0   r1   r   r   r   r   r   r   r   r     s+    T $ 	& 	&r   r   c                   >    \ rS rSrSrS r\S 5       r\S 5       rSr	g)GetUsersResulti:  z6Represents the result of the ``auth.get_users()`` API.c                     Xl         X l        g)zConstructs a `GetUsersResult` object.

Args:
    users: List of `UserRecord` instances.
    not_found: List of `UserIdentifier` instances.
N)_users
_not_found)r   users	not_founds      r   r   GetUsersResult.__init__=  s     #r   c                     U R                   $ )zSet of `UserRecord` instances, corresponding to the set of users
that were requested. Only users that were found are listed here. The
result set is unordered.
)r   r*   s    r   r   GetUsersResult.usersG  s     {{r   c                     U R                   $ )zFSet of `UserIdentifier` instances that were requested, but not
found.
)r   r*   s    r   r   GetUsersResult.not_foundO  s    
 r   )r   r   N)
r   r   r   r   r0   r   r1   r   r   r   r   r   r   r   r   :  s2    @$    r   r   c                   Z    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	S r
S rS	rg
)ListUsersPageiW  aD  Represents a page of user records exported from a Firebase project.

Provides methods for traversing the user accounts included in this page, as well as retrieving
subsequent pages of users. The iterator returned by ``iterate_all()`` can be used to iterate
through all users in the Firebase project starting from this page.
c                 6    Xl         X0l        U" X#5      U l        g r   )	_download_max_results_current)r   download
page_tokenmax_resultss       r   r   ListUsersPage.__init___  s    !' 9r   c                 x    U R                   R                  S/ 5       Vs/ s H  n[        U5      PM     sn$ s  snf )zBA list of ``ExportedUserRecord`` instances available in this page.r   )r   rV   r   )r   users     r   r   ListUsersPage.usersd  s6     6:]]5F5FwPR5ST5ST"4(5STTTs   7c                 :    U R                   R                  SS5      $ )zKPage token string for the next page (empty string indicates no more pages).nextPageToken )r   rV   r*   s    r   next_page_tokenListUsersPage.next_page_tokeni  s     }}  "55r   c                 ,    [        U R                  5      $ )z6A boolean indicating whether more pages are available.)rr   r   r*   s    r   has_next_pageListUsersPage.has_next_pagen  s     D(())r   c                 |    U R                   (       a+  [        U R                  U R                  U R                  5      $ g)zRetrieves the next page of user accounts, if available.

Returns:
    ListUsersPage: Next page of users, or None if this is the last page.
N)r   r   r   r   r   r*   s    r   get_next_pageListUsersPage.get_next_pages  s/      1E1EtGXGXYYr   c                     [        U 5      $ )a-  Retrieves an iterator for user accounts.

Returned iterator will iterate through all the user accounts in the Firebase project
starting from this page. The iterator will never buffer more than one page of users
in memory at a time.

Returns:
    iterator: An iterator of ExportedUserRecord instances.
)_UserIteratorr*   s    r   iterate_allListUsersPage.iterate_all}  s     T""r   )r   r   r   N)r   r   r   r   r0   r   r1   r   r   r   r   r   r   r   r   r   r   r   W  sT    :
 U U 6 6 * *
#r   r   c                   N    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	Sr
g)	DeleteUsersResulti  z9Represents the result of the ``auth.delete_users()`` API.c                 n    UR                   nU[        U5      -
  U l        [        U5      U l        X0l        g)zConstructs a `DeleteUsersResult` object.

Args:
  result: The proto response, wrapped in a
    `BatchDeleteAccountsResponse` instance.
  total: Total integer number of deletion attempts.
N)errorslen_success_count_failure_count_errors)r   resulttotalr   s       r   r   DeleteUsersResult.__init__  s/     #c&k1!&kr   c                     U R                   $ )zReturns the number of users that were deleted successfully (possibly
zero).

Users that did not exist prior to calling `delete_users()` are
considered to be successfully deleted.
)r   r*   s    r   success_countDeleteUsersResult.success_count  s     """r   c                     U R                   $ )zGReturns the number of users that failed to be deleted (possibly
zero).
)r   r*   s    r   failure_countDeleteUsersResult.failure_count  s    
 """r   c                     U R                   $ )zA list of `auth.ErrorInfo` instances describing the errors that
were encountered during the deletion. Length of this list is equal to
`failure_count`.
)r   r*   s    r   r   DeleteUsersResult.errors  s     ||r   )r   r   r   N)r   r   r   r   r0   r   r1   r   r   r   r   r   r   r   r   r     sF    C # # # #  r   r   c                   "    \ rS rSrSrSS jrSrg)BatchDeleteAccountsResponsei  z2Represents the results of a `delete_users()` call.Nc                 n    U(       a"  U Vs/ s H  n[        U5      PM     snU l        g/ U l        gs  snf )a1  Constructs a `BatchDeleteAccountsResponse` instance, corresponding to
the JSON representing the `BatchDeleteAccountsResponse` proto.

Args:
    errors: List of dictionaries, with each dictionary representing an
        `ErrorInfo` instance as returned by the server. `None` implies
        an empty list.
N)r	   r   )r   r   errs      r   r   $BatchDeleteAccountsResponse.__init__  s*     =C8#y~88s   2)r   r   r   r   r   r   r0   r   r   r   r   r   r   r     s    <	Kr   r   c                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
rU =r$ )r   i  zRContains metadata regarding how a user is known by a particular identity provider.c                    > [         [        U ]  5         [        U[        5      (       d  [        SR                  U5      5      eUR                  S5      (       d  [        S5      eXl        g )NrN   rawIdrP   )	rQ   r   r   rR   rS   rT   rU   rV   rW   rX   s     r   r   ProviderUserInfo.__init__  sV    .0$%%PWWX\]^^xx  ABB
r   c                 8    U R                   R                  S5      $ )Nr   r]   r*   s    r   r8   ProviderUserInfo.uid      zz~~g&&r   c                 8    U R                   R                  S5      $ )Nr`   r]   r*   s    r   r<   ProviderUserInfo.display_name      zz~~m,,r   c                 8    U R                   R                  S5      $ )Nr?   r]   r*   s    r   r?   ProviderUserInfo.email  r   r   c                 8    U R                   R                  S5      $ )Nrf   r]   r*   s    r   rB   ProviderUserInfo.phone_number  r   r   c                 8    U R                   R                  S5      $ )Nri   r]   r*   s    r   rE   ProviderUserInfo.photo_url  s    zz~~j))r   c                 8    U R                   R                  S5      $ )N
providerIdr]   r*   s    r   rH   ProviderUserInfo.provider_id  s    zz~~l++r   r   )r   r   r   r   r0   r   r1   r8   r<   r?   rB   rE   rH   r   r   r   s   @r   r   r     s    \ ' ' - - ' ' - - * * , ,r   r   c                   &    \ rS rSrSr  SS jrSrg)ActionCodeSettingsi  zContains required continue/state URL with optional Android and iOS settings.
Used when invoking the email action link generation APIs.
Nc                 X    Xl         X l        X0l        X@l        XPl        X`l        Xpl        g r   )urlhandle_code_in_appdynamic_link_domainios_bundle_idandroid_package_nameandroid_install_appandroid_minimum_version)r   r  r  r  r  r  r  r	  s           r   r   ActionCodeSettings.__init__  s+    "4#6 *$8!#6 '>$r   )r  r	  r  r  r  r  r  )NNNNNNr   r   r   r   r  r    s     ^b^b?r   r  c                 `   0 nU R                   (       d  [        S5      e [        R                  " U R                   5      nUR                  (       d$  [        SR                  U R                   5      5      eU R                   US'   U R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US'   U R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US'   U R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US	'   U R                  (       d  U R                  (       a  U R                  (       d  [        S
5      eU R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US'   U R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US'   U R                  bR  [        U R                  [        5      (       d$  [        SR                  U R                  5      5      eU R                  US'   U$ ! [         a%    [        SR                  U R                   5      5      ef = f)zValidates the provided action code settings for email link generation and
populates the REST api parameters.

settings - ``ActionCodeSettings`` object provided to be encoded
returns  - dict of parameters to be passed for link gereration.
z%Dynamic action links url is mandatoryz*Malformed dynamic action links url: "{0}".continueUrlz2Invalid value provided for handle_code_in_app: {0}canHandleCodeInAppz3Invalid value provided for dynamic_link_domain: {0}dynamicLinkDomainz-Invalid value provided for ios_bundle_id: {0}iOSBundleIdzGAndroid package name is required when specifying other Android settingsz4Invalid value provided for android_package_name: {0}androidPackageNamez7Invalid value provided for android_minimum_version: {0}androidMinimumVersionz3Invalid value provided for android_install_app: {0}androidInstallApp)r  rT   r   urlparsenetlocrU   	Exceptionr  rR   rr   r  strr  r	  r  r  )settings
parametersr   s      r   encode_action_code_settingsr    s    J<<@AA\-}}IPPQYQ]Q]^__$,LL
=!
 "".(55t<<Q$fX%@%@AC C+3+F+F
'( ##/(66<<R$fX%A%ABD D*2*F*F
&' )(00#66L$fX%;%;<> >$,$:$:
=! 	((H,H,H--bcc$$0(77==S$fX%B%BCE E+3+H+H
'(''3(::C@@V$fX%E%EFH H.6.N.N
*+##/(66==R$fX%A%ABD D*2*F*F
&'_  \ELLX\\Z[[\s   A$K> >/L-c                       \ rS rSrSrSrSS jrS rS rS\	4S jr
  SS	 jr   SS
 jrS rSS jrSS jrSS jrS rSrg)UserManageri;  zBProvides methods for interacting with the Google Identity Toolkit.z)https://identitytoolkit.googleapis.com/v1Nc                     Xl         U=(       d    U R                  nSR                  XR5      U l        U(       a%  U =R                  SR                  U5      -  sl        g g )Nz{0}/projects/{1}z/tenants/{0})http_clientID_TOOLKIT_URLrU   base_url)r   r  
project_idr   url_override
url_prefixs         r   r   UserManager.__init__@  sK    &!8T%8%8
*11*IMM^229==M r   c                    SU;   a+  UR                  S5      Sp2S[        R                  " USS9/0nO|SU;   a+  UR                  S5      Sp2S[        R                  " USS9/0nOKSU;   a+  UR                  S5      Sp2S	[        R                  " USS9/0nO[        S
R                  U5      5      eU R                  SSUS9u  pVU(       a  UR                  S5      (       d$  [        R                  " SR                  X25      US9eUS   S   $ )z5Gets the user data corresponding to the provided key.r8   zuser IDrO   Trequiredr?   rB   zphone numberrf   z#Unsupported keyword arguments: {0}.post/accounts:lookupr   r   z/No user record found for the provided {0}: {1}.http_responser   )
popr   validate_uidvalidate_emailvalidate_phone	TypeErrorrU   _make_requestrV   UserNotFoundError)r   kwargsr   key_typepayloadbody	http_resps          r   get_userUserManager.get_userG  s   F?"JJu-y K$<$<S4$P#QRG"JJw/+"<"<S4"P!QRGv%"JJ~6$(B(B3QU(V'WXGAHHPQQ,,V5Gg,V488G,,//AHHW') ) G}Qr   c                 f   U(       d  / $ [        U5      S:  a  [        S5      e[        [        5      nU GH.  n[	        U[
        R                  5      (       a   US   R                  UR                  5        MC  [	        U[
        R                  5      (       a   US   R                  UR                  5        M  [	        U[
        R                  5      (       a   US   R                  UR                  5        M  [	        U[
        R                  5      (       a.  US   R                  UR                  UR                  S.5        GM  [        SR!                  [#        U5      5      5      e   U R%                  S	S
US9u  pEUR&                  (       d  [(        R*                  " SUS9eUR-                  S/ 5      $ )a  Looks up multiple users by their identifiers (uid, email, etc.)

Args:
    identifiers: UserIdentifier[]: The identifiers indicating the user
        to be looked up. Must have <= 100 entries.

Returns:
    list[dict[string, string]]: List of dicts representing the JSON
    `UserInfo` responses from the server.

Raises:
    ValueError: If any of the identifiers are invalid or if more than
        100 identifiers are specified.
    UnexpectedResponseError: If the backend server responds with an
        unexpected message.
d   z1`identifiers` parameter must have <= 100 entries.rO   r?   rf   federatedUserId)r   r   z9Invalid entry in "identifiers" list. Unsupported type: {}r'  r(  r)  zFailed to get users.r*  r   )r   rT   r   listrR   r   UidIdentifierappendr8   EmailIdentifierr?   PhoneIdentifierrB   ProviderIdentifierrH   provider_uidrU   typer1  okr   UnexpectedResponseErrorrV   )r   identifiersr5  
identifierr6  r7  s         r   	get_usersUserManager.get_users\  sq   " I{c!PQQd#%J*&6&D&DEE	"))*..9J(8(H(HII ''
(8(89J(8(H(HII&--j.E.EFJ(8(K(KLL)*11","8"8'443 
 !OVD,-/ / &" ,,&W - 6||55&iA Axx$$r   c                 :   Ub'  [        U[        5      (       a  U(       d  [        S5      e[        U[        5      (       d  [        S5      eUS:  d
  U[        :  a  [        SR                  [        5      5      eSU0nU(       a  XS'   U R                  SSUS	9u  pEU$ )
zRetrieves a batch of users.z&Page token must be a non-empty string.zMax results must be an integer.   z5Max results must be a positive integer less than {0}.
maxResultsr   rV   z/accounts:batchGet)params)rR   r  rT   rz   MAX_LIST_USERS_RESULTSrU   r1  )r   r   r   r5  r6  _s         r   
list_usersUserManager.list_users  s    !j#..j !IJJ+s++>???k,BBv457 7  -'1O$$$U,@$Qr   c	           
      J   [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R
                  " U5      [         R                  " U5      Ub  [        U5      OSUb  [        U5      OSS.n	U	R                  5        V
Vs0 s H  u  pUc  M
  X_M     n	n
nU R                  SSU	S9u  pU(       a  UR                  S5      (       d  [         R                  " SUS9eUR                  S5      $ s  snn
f )	z9Creates a new user account with the specified properties.N)rO   r`   r?   rf   ri   passwordrp   rv   r'  z	/accountsr)  rO   zFailed to create new user.r*  )r   r-  validate_display_namer.  r/  validate_photo_urlvalidate_passwordrr   itemsr1  rV   rF  )r   r8   r<   r?   rB   rE   rT  rv   rs   r5  kvr6  r7  s                 r   create_userUserManager.create_user  s     #//4&<<\J //6&55lC#66yA#55h?5C5OT.1UY*2*>XD	
 %,MMOEODAq414OE,,V[w,O488I..55,IG Gxx	"" Fs   3	D Dc                    [         R                  " USS9[         R                  " U5      [         R                  " U5      [         R                  " U	S5      Ub  [        U5      OSUb  [        U5      OSS.n/ n[         R                  " U5      nUb4  U[        L a  UR                  S5        O[         R                  " U5      US'   Ub4  U[        L a  UR                  S5        O[         R                  " U5      US	'   U(       a  XS
'   Ub4  U[        L a  UR                  S5        O[         R                  " U5      US'   U
bQ  U
[        L a  0 n
[        U
[        5      (       a  [        R                  " U
5      OU
n[         R                   " U5      US'   U(       a  [#        [%        U5      5      US'   UR'                  5        VVs0 s H  u  nnUc  M  UU_M     nnnU R)                  SSUS9u  nnU(       a  UR+                  S5      (       d$  [         R,                  " SR/                  U5      US9eUR+                  S5      $ s  snnf )z>Updates an existing user account with the specified propertiesTr%  r{   N)rO   r?   rT  ry   rp   disableUserDISPLAY_NAMEr`   	PHOTO_URLri   deleteAttributephonerf   r   deleteProviderr'  z/accounts:updater)  rO   zFailed to update user: {0}.r*  )r   r-  r.  rW  r$   rr   validate_provider_idsDELETE_ATTRIBUTEr?  rU  rV  r/  rR   rS   r   dumpsvalidate_custom_claimsr=  setrX  r1  rV   rF  rU   )r   r8   r<   r?   rB   rE   rT  rv   rs   r{   r   providers_to_deleter5  removeremove_providerjson_claimsrY  rZ  r6  r7  s                       r   update_userUserManager.update_user  s   
 #//dC //6#55h?%88mT5C5OT.1UY-5-A4>t
 %;;<OP#//n-)4)J)J<)X& ,,k*&1&D&DY&O
#)/%&#//&&w/)4)C)CL)Q&$ 00 "7At8% 8%$**]3*7 *5*L*L[*YG&'(,S-A(BG$%$+MMOEODAqq41a4OE,,V5Gg,Vi488I..55-44S9T Txx	"" Fs   
IIc                     [         R                  " USS9  U R                  SSSU0S9u  p#U(       a  UR                  S5      (       d$  [         R                  " SR                  U5      US	9eg
)z5Deletes the user identified by the specified user ID.Tr%  r'  z/accounts:deleterO   r)  kindzFailed to delete user: {0}.r*  N)r   r-  r1  rV   rF  rU   )r   r8   r6  r7  s       r   delete_userUserManager.delete_user  sm      t4,,V5Gy[^N_,`488F++55-44S9T T ,r   c                 H   U(       d
  [        5       $ [        U5      S:  a  [        S5      eU H  n[        R                  " USS9  M     U R                  SSXS.S9u  pE[        U[        5      (       d  [        R                  " S	US
9e[        UR                  S/ 5      5      $ )as  Deletes the users identified by the specified user ids.

Args:
    uids: A list of strings indicating the uids of the users to be deleted.
        Must have <= 1000 entries.
    force_delete: Optional parameter that indicates if users should be
        deleted, even if they're not disabled. Defaults to False.


Returns:
    BatchDeleteAccountsResponse: Server's proto response, wrapped in a
    python object.

Raises:
    ValueError: If any of the identifiers are invalid or if more than 1000
        identifiers are specified.
    UnexpectedResponseError: If the backend server responds with an
        unexpected message.
r
   z*`uids` paramter must have <= 1000 entries.Tr%  r'  z/accounts:batchDelete)localIdsforcer)  zAUnexpected response from server while attempting to delete users.r*  r   )
r   r   rT   r   r-  r1  rR   rS   rF  rV   )r   uidsforce_deleter8   r6  r7  s         r   delete_usersUserManager.delete_users  s    ( .00t9tIJJC$$S48  ,,V5L?C2[ - ]$%%55S') ) +488Hb+ABBr   c           	          U(       a  [        U5      [        :  a  [        SR                  [        5      5      e[	        U Vs/ s H"  n[        U[        R                  5      (       + PM$     sn5      (       a  [        S5      e SU Vs/ s H  o3R                  5       PM     sn0n[	        US    Vs/ s H  nSU;   PM
     sn5      (       aI  [        U[        R                  5      (       d  [        S5      eUR                  UR                  5       5        U R                  SSUS	9u  pV[        U[        5      (       d  [        R                  " S
US9eU$ s  snf ! [         a    [        S5      ef = fs  snf s  snf )z1Imports the given list of users to Firebase Auth.z>Users must be a non-empty list with no more than {0} elements.z%One or more user objects are invalid.zusers must be iterabler   r   z<A UserImportHash is required to import users with passwords.r'  z/accounts:batchCreater)  zFailed to import users.r*  )r   MAX_IMPORT_USERS_SIZErT   rU   anyrR   r   ImportUserRecordr0  to_dictUserImportHashupdater1  rS   r   rF  )r   r   hash_algur5  r6  r7  s          r   import_usersUserManager.import_users  sZ   	7CJ)>> T[[-/0 0 eTe
1l&C&CDDeTUU !HII V
 %8%QYY[%89WW-=>-=!#-=>??h(C(CDD !_``NN8++-.,,V5LSZ,[$%%55)D D U 	7566	7 9>s*   AE )E,E 	E32E8E E0c                 L   [         R                  " U5      [         R                  " U5      SS.nU(       a  UR                  [	        U5      5        U R                  SSUS9u  pVU(       a  UR                  S5      (       d  [         R                  " SUS9eUR                  S5      $ )	a  Fetches the email action links for types

Args:
    action_type: String. Valid values ['VERIFY_EMAIL', 'EMAIL_SIGNIN', 'PASSWORD_RESET']
    email: Email of the user for which the action is performed
    action_code_settings: ``ActionCodeSettings`` object or dict (optional). Defines whether
        the link is to be handled by a mobile app and the additional state information to be
        passed in the deep link, etc.
Returns:
    link_url: action url to be emailed to the user

Raises:
    UnexpectedResponseError: If the backend server responds with an unexpected message
    FirebaseError: If an error occurs while generating the link
    ValueError: If the provided arguments are invalid
T)requestTyper?   returnOobLinkr'  z/accounts:sendOobCoder)  oobLinkz%Failed to generate email action link.r*  )r   validate_action_typer.  r  r  r1  rV   rF  )r   action_typer?   action_code_settingsr5  r6  r7  s          r   generate_email_action_link&UserManager.generate_email_action_link'  s    $ ';;KH //6!
  NN67KLM,,V5LSZ,[488I..557yR Rxx	""r   c                     SR                  U R                  U5      n U R                  R                  " X40 UD6$ ! [        R
                  R                   a  n[        R                  " U5      eS nAff = f)Nz{0}{1})	rU   r  r  body_and_responserequests
exceptionsRequestExceptionr   handle_auth_backend_error)r   methodpathr3  r  errors         r   r1  UserManager._make_requestG  sd    oodmmT2	?##55fLVLL""33 	?77>>	?s   ; A4A//A4)r  r  )NN)NNNNNNNN)
NNNNNNNNNN)Fr   )r   r   r   r   r0   r  r   r8  rI  rO  rQ  r[  rm  rq  rx  r  r  r1  r   r   r   r   r  r  ;  sf    L@N> *-%^ %)6L $ QUQU#( LPQUNR1#fT"CH.#@?r   r  c                   $    \ rS rSr\S 5       rSrg)r   iO  c                 .    U R                   R                  $ r   )_current_pager   r*   s    r   rX  _UserIterator.itemsQ  s    !!'''r   r   N)r   r   r   r   r1   rX  r   r   r   r   r   r   O  s    ( (r   r   )#r0   base64collectionsr   r   urllibr   r  firebase_adminr   r   r   r   firebase_admin._user_importr	   rO  r{  	b64encoder   r   re  r   r3   rK   r   r   r   r   r   r   r  r  r  PageIteratorr   r   r   r   <module>r     s    +  #    & # + ' 1   ,' ' ST &, &,R&" &"RU* U*p &  &F :0# 0#f' 'TK K!,x !,H? ? AHQ? Q?h(K,, (r   