
    h(G                        d 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Z	dZ
 eg d          Z eg d	          Z G d
 d          Zd Zd ZdCdZdCdZdCdZdCdZdCdZdCdZdDdZdDdZdCdZdCdZdEdZd Zd ZdCdZd ZdCdZ d  Z! G d! d"ej"                  Z# G d# d$ej"                  Z$ G d% d&ej%                  Z& G d' d(ej'                  Z( G d) d*ej'                  Z) G d+ d,ej"                  Z* G d- d.ej+                  Z, G d/ d0ej-                  Z. G d1 d2ej-                  Z/ G d3 d4ej-                  Z0 G d5 d6ej'                  Z1 G d7 d8ej-                  Z2 G d9 d:ej'                  Z3 G d; d<ej4                  Z5 G d= d>ej4                  Z6e2e$e#e$e/e&e(e)e*e0e.e5e6d?Z7d@ Z8dA Z9dB Z:dS )FzFirebase auth utils.    N)parse)
exceptions)_utilsFIREBASE_AUTH_EMULATOR_HOSTi  )acramrat_hashaud	auth_timeazpcnfc_hashexpiatissjtinbfnoncesubfirebase)VERIFY_EMAILEMAIL_SIGNINPASSWORD_RESETc                   :    e Zd ZdZd Zd Zd Zed             ZdS )PageIteratora(  An iterator that allows iterating over a sequence of items, one at a time.

    This implementation loads a page of items into memory, and iterates on them. When the whole
    page has been traversed, it loads another page. This class never keeps more than one page
    of entries in memory.
    c                 D    |st          d          || _        d | _        d S )NzCurrent page must not be None.)
ValueError_current_page_iter)selfcurrent_pages     ^/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/firebase_admin/_auth_utils.py__init__zPageIterator.__init__+   s,     	?=>>>)


    c                 <   | j         t          | j                  | _         	 t          | j                   S # t          $ r[ | j        j        rM| j                                        | _        t          | j                  | _         t          | j                   cY S  w xY wN)r   iteritemsnextStopIterationr   has_next_pageget_next_pager    s    r"   __next__zPageIterator.__next__2   s    :dj))DJ		
### 	 	 	!/ (%)%7%E%E%G%G"!$*--
DJ'''''	s   6 A!BBc                     | S r&    r-   s    r"   __iter__zPageIterator.__iter__A   s    r$   c                     t           r&   )NotImplementedErrorr-   s    r"   r(   zPageIterator.itemsD   s    !!r$   N)	__name__
__module____qualname____doc__r#   r.   r1   propertyr(   r0   r$   r"   r   r   #   sf                " " X" " "r$   r   c                  |    t          j        t          d          } | rd| v rt          dt           d|  d          | S )N z//zInvalid z: "z%". It must follow format "host:port".)osgetenvEMULATOR_HOST_ENV_VARr   )emulator_hosts    r"   get_emulator_hostr?   I   sc    I3R88M 2..1, 1 1 1 1 12 2 	2 r$   c                  &    t                      dk    S )Nr:   )r?   r0   r$   r"   is_emulatedrA   R   s    "$$r$   Fc                     | |sd S t          | t                    r| rt          |           dk    rt          d|  d          | S )N   zInvalid uid: "zG". The uid must be a non-empty string with no more than 128 characters.
isinstancestrlenr   )uidrequireds     r"   validate_uidrJ   V   sf    
{8{tc3 s c#hhnnS     	 Jr$   c                     | |sd S t          | t                    r| st          d|  d          |                     d          }t	          |          dk    s|d         r|d         st          d|  d          | S )	NzInvalid email: "z$". Email must be a non-empty string.@   r      z!Malformed email address string: "".)rE   rF   r   splitrG   )emailrI   partss      r"   validate_emailrS   _   s    }X}teS!! L LJuJJJL L 	LKKE
5zzQeAheAhFUFFFGGGLr$   c                     | |sdS t          | t                    r| st          d|  d          |                     d          rt	          j        d|           st          d|  d          | S )a	  Validates the specified phone number.

    Phone number vlidation is very lax here. Backend will enforce E.164 spec compliance, and
    normalize accordingly. Here we check if the number starts with + sign, and contains at
    least one alphanumeric character.
    NzInvalid phone number: "z+". Phone number must be a non-empty string.+z[a-zA-Z0-9]z<". Phone number must be a valid, E.164 compliant identifier.)rE   rF   r   
startswithresearch)phonerI   s     r"   validate_phonerZ   j   s     }X}teS!! Z ZXeXXXZ Z 	ZC   %	-(G(G %$e $ $ $% % 	% Lr$   c                     | |sd S t          | t                    rt          |           dk     rt          d          | S )N   zNInvalid password string. Password must be a string at least 6 characters long.rD   )passwordrI   s     r"   validate_passwordr^   |   sR    th$$ ^H(9(9\^ ^ 	^Or$   c                 d    | |sd S t          | t                    r| st          | d          | S )Nz# must be a non-empty byte sequence.)rE   bytesr   )valuelabelrI   s      r"   validate_bytesrc      sG    }X}teU## H5 HEFFFGGGLr$   c                 f    | |sd S t          | t                    r| st          d|  d          | S )NzInvalid display name: "z+". Display name must be a non-empty string.rE   rF   r   )display_namerI   s     r"   validate_display_namerg      s[    HtlC((  l     	 r$   Tc                 f    | |sd S t          | t                    r| st          d|  d          | S )NzInvalid provider ID: "z*". Provider ID must be a non-empty string.re   )provider_idrI   s     r"   validate_provider_idrj      sV    8tk3'' ^{ ^\[\\\^ ^ 	^r$   c                 f    | |sd S t          | t                    r| st          d|  d          | S )NzInvalid provider UID: "z+". Provider UID must be a non-empty string.re   )provider_uidrI   s     r"   validate_provider_uidrm      sV    HtlC(( a a_l___a a 	ar$   c                    | |sdS t          | t                    r| st          d|  d          	 t          j        |           }|j        st          d|  d          | S # t          $ r}t          d|  d          |d}~ww xY w)z*Parses and validates the given URL string.NzInvalid photo URL: "z(". Photo URL must be a non-empty string.zMalformed photo URL: "rO   )rE   rF   r   r   urlparsenetloc	Exception)	photo_urlrI   parsederrs       r"   validate_photo_urlru      s    ti%% XY XV9VVVX X 	XJ	**} 	ECiCCCDDD J J J?)???@@cIJs   /A" "
B,B  Bc                 (   | |sdS t          | t                    rt          d          	 t          |           }n&# t          $ r}t          d|  d          |d}~ww xY w|| k    rt          | d          |dk    rt          | d          |S )zJValidates the given timestamp value. Timestamps must be positive integers.Nz%Boolean value specified as timestamp.z"Invalid type for timestamp value: ., must be a numeric value and a whole number.r   z' timestamp must be a positive interger.rE   boolr   int	TypeError)	timestamprb   rI   timestamp_intrt   s        r"   validate_timestampr      s    t)T"" B@AAAUI U U UJiJJJKKQTTU	!!EOOOPPPEJJJKKK   < 
AAAc                 l   | t          | t                    rt          d|  d          	 t          |           }n&# t          $ r}t          d|  d          |d}~ww xY w|| k    rt          | d          |||k     rt          | d| d          |||k    rt          | d| d          |S )au  Validates that the given value represents an integer.

    There are several ways to represent an integer in Python (e.g. 2, 2L, 2.0). This method allows
    for all such representations except for booleans. Booleans also behave like integers, but
    always translate to 1 and 0. Passing a boolean to an API that expects integers is most likely
    a developer error.
    Nz Invalid type for integer value: rw   rx   z must not be smaller than z must not be larger than ry   )ra   rb   lowhighval_intrt   s         r"   validate_intr      s    }
5$//}DEDDDEEEOe** O O ODEDDDEE3NO%EOOOPPP
7S==ECCSCCCDDDGdNNECCDCCCDDDNr   c                 \    t          | t                    st          d| d|  d          | S )z+Validates that the given value is a string.Invalid type for : rw   re   ra   rb   s     r"   validate_stringr      s<    eS!! @>U>>e>>>???Lr$   c                 \    t          | t                    st          d| d|  d          | S )z,Validates that the given value is a boolean.r   r   rw   )rE   rz   r   r   s     r"   validate_booleanr      s<    eT"" @>U>>e>>>???Lr$   c                    | |sdS t          |           }t          |          t          k    rt          dt           d          	 t	          j        |          }n"# t          $ r}t          d          |d}~ww xY wt          |t                    st          d          t          
                    t          |                                                    }t          |          dk    r5d                    t          |                    }t          d| d	          t          |          dk    r%t          d
|                                 d          |S )zValidates the specified custom claims.

    Custom claims must be specified as a JSON string. The string must not exceed 1000
    characters, and the parsed JSON payload must not contain reserved JWT claims.
    Nz&Custom claims payload must not exceed z characters.z-Failed to parse custom claims string as JSON.z1Custom claims must be parseable as a JSON object.rN   , zClaims "z$" are reserved, and must not be set.zClaim "z#" is reserved, and must not be set.)rF   rG   MAX_CLAIMS_PAYLOAD_SIZEr   jsonloadsrq   rE   dictRESERVED_CLAIMSintersectionsetkeysjoinsortedpop)custom_claimsrI   
claims_strrs   rt   invalid_claimsjoineds          r"   validate_custom_claimsr      sw    Xt]##J
:000Z5LZZZ\ \ 	\SJ'' S S SHIIsRS fd## NLMMM$11#fkkmm2D2DEEN
>Q6.1122PFPPPQQQ
>aOn((**OOOQ Q 	Qs   A 
A;&A66A;c                 r    | t           vr-t          d|  dd                    t                                | S )Nz*Invalid action type provided action_type: z. Valid values are r   )VALID_EMAIL_ACTION_TYPESr   r   )action_types    r"   validate_action_typer     sS    2225 5 5yy1225 56 6 	6 r$   c                 Z    | s|rt          d          g S | D ]}t          |d           | S )Nz5Invalid provider IDs. Provider ids should be providedT)r   rj   )provider_idsrI   ri   s      r"   validate_provider_idsr   	  sO      	VTUUU	# 0 0[$////r$   c                 
   g }|                                  D ]^\  }}t          |t                    r/t          |          }|D ]}|                    | d|            I|                    |           _t          |          S )z6Creates an update mask list from the given dictionary.rw   )r(   rE   r   build_update_maskappendr   )paramsmaskkeyra   
child_maskchilds         r"   r   r     s    Dllnn  
UeT"" 	*511J# . .s,,U,,----. KK$<<r$   c                       e Zd ZdZdZd ZdS )UidAlreadyExistsErrorz.The user with the provided uid already exists.z-The user with the provided uid already existsc                 J    t           j                            | |||           d S r&   r   AlreadyExistsErrorr#   r    messagecausehttp_responses       r"   r#   zUidAlreadyExistsError.__init__%  %    %..tWe]SSSSSr$   Nr4   r5   r6   r7   default_messager#   r0   r$   r"   r   r      s3        88EOT T T T Tr$   r   c                       e Zd ZdZdZd ZdS )EmailAlreadyExistsErrorz0The user with the provided email already exists.z/The user with the provided email already existsc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   z EmailAlreadyExistsError.__init__.  r   r$   Nr   r0   r$   r"   r   r   )  s3        ::GOT T T T Tr$   r   c                       e Zd ZdZdZd ZdS )InsufficientPermissionErrorzEThe credential used to initialize the SDK lacks required permissions.zThe credential used to initialize the SDK has insufficient permissions to perform the requested operation. See https://firebase.google.com/docs/admin/setup for details on how to initialize the Admin SDK with appropriate permissionsc                 J    t           j                            | |||           d S r&   )r   PermissionDeniedErrorr#   r   s       r"   r#   z$InsufficientPermissionError.__init__:  s%    (11$VVVVVr$   Nr   r0   r$   r"   r   r   2  s6        OOYO
W W W W Wr$   r   c                       e Zd ZdZdZd ZdS )InvalidDynamicLinkDomainErrorz<Dynamic link domain in ActionCodeSettings is not authorized.zEDynamic link domain specified in ActionCodeSettings is not authorizedc                 J    t           j                            | |||           d S r&   r   InvalidArgumentErrorr#   r   s       r"   r#   z&InvalidDynamicLinkDomainError.__init__C  %    '00w}UUUUUr$   Nr   r0   r$   r"   r   r   >  s3        FF]OV V V V Vr$   r   c                       e Zd ZdZdZddZdS )InvalidIdTokenErrorz7The provided ID token is not a valid Firebase ID token.z The provided ID token is invalidNc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   zInvalidIdTokenError.__init__L  r   r$   NNr   r0   r$   r"   r   r   G  s9        AA8OV V V V V Vr$   r   c                       e Zd ZdZdZd ZdS )PhoneNumberAlreadyExistsErrorz7The user with the provided phone number already exists.z6The user with the provided phone number already existsc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   z&PhoneNumberAlreadyExistsError.__init__U  r   r$   Nr   r0   r$   r"   r   r   P  s3        AANOT T T T Tr$   r   c                       e Zd ZdZddZdS )UnexpectedResponseErrorzCBackend service responded with an unexpected or malformed response.Nc                 J    t           j                            | |||           d S r&   )r   UnknownErrorr#   r   s       r"   r#   z UnexpectedResponseError.__init__\  s%    ((w}MMMMMr$   r   r4   r5   r6   r7   r#   r0   r$   r"   r   r   Y  s4        MMN N N N N Nr$   r   c                       e Zd ZdZdZddZdS )UserNotFoundErrorz2No user record found for the specified identifier.z-No user record found for the given identifierNc                 J    t           j                            | |||           d S r&   r   NotFoundErrorr#   r   s       r"   r#   zUserNotFoundError.__init__e  %     ))$NNNNNr$   r   r   r0   r$   r"   r   r   `  s9        <<EOO O O O O Or$   r   c                       e Zd ZdZdZddZdS )EmailNotFoundErrorz-No user record found for the specified email.z(No user record found for the given emailNc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   zEmailNotFoundError.__init__n  r   r$   r   r   r0   r$   r"   r   r   i  9        77@OO O O O O Or$   r   c                       e Zd ZdZdZddZdS )TenantNotFoundErrorz-No tenant found for the specified identifier.z(No tenant found for the given identifierNc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   zTenantNotFoundError.__init__w  r   r$   r   r   r0   r$   r"   r   r   r  r   r$   r   c                       e Zd ZdZd ZdS )TenantIdMismatchErrorz4Missing or invalid tenant ID field in the given JWT.c                 F    t           j                            | |           d S r&   r   )r    r   s     r"   r#   zTenantIdMismatchError.__init__~  s!    '00w?????r$   Nr   r0   r$   r"   r   r   {  s.        >>@ @ @ @ @r$   r   c                       e Zd ZdZdZddZdS )ConfigurationNotFoundErrorz4No auth provider found for the specified identifier.z/No auth provider found for the given identifierNc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   z#ConfigurationNotFoundError.__init__  r   r$   r   r   r0   r$   r"   r   r     s9        >>GOO O O O O Or$   r   c                       e Zd ZdZdZddZdS )UserDisabledErrorz8An operation failed due to a user record being disabled.zThe user record is disabledNc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   zUserDisabledError.__init__  r   r$   r   r   r0   r$   r"   r   r     s9        BB3OV V V V V Vr$   r   c                       e Zd ZdZddZdS )TooManyAttemptsTryLaterErrorz*Rate limited because of too many attempts.Nc                 J    t           j                            | |||           d S r&   r   ResourceExhaustedErrorr#   r   s       r"   r#   z%TooManyAttemptsTryLaterError.__init__  %    )224%WWWWWr$   r   r   r0   r$   r"   r   r     s4        44X X X X X Xr$   r   c                       e Zd ZdZddZdS )ResetPasswordExceedLimitErrorz,Reset password emails exceeded their limits.Nc                 J    t           j                            | |||           d S r&   r   r   s       r"   r#   z&ResetPasswordExceedLimitError.__init__  r   r$   r   r   r0   r$   r"   r   r     s4        66X X X X X Xr$   r   )CONFIGURATION_NOT_FOUNDDUPLICATE_EMAILDUPLICATE_LOCAL_IDEMAIL_EXISTSEMAIL_NOT_FOUNDINSUFFICIENT_PERMISSIONINVALID_DYNAMIC_LINK_DOMAININVALID_ID_TOKENPHONE_NUMBER_EXISTSTENANT_NOT_FOUNDUSER_NOT_FOUNDTOO_MANY_ATTEMPTS_TRY_LATERRESET_PASSWORD_EXCEED_LIMITc                    | j         t          j        |           S t          | j                   \  }}|s7d| j         j                                         }t          j        | |          S t                              |          }t          |||          }|st          j        | |          S  ||| | j                   S )zWConverts a requests error received from the Firebase Auth service into a FirebaseError.NzUnexpected error response: )r   )r   r   )	responser   handle_requests_error_parse_error_bodycontentdecode_CODE_TO_EXC_TYPEget_build_error_message)errorcodecustom_messagemsgexc_types        r"   handle_auth_backend_errorr    s    ~+E222,U^<<D. @MEN,B,I,I,K,KMM+E3???? $$T**H
tX~
>
>C @+E3????8CuENCCCCr$   c                    i }	 |                                  }t          |t                    r|                    di           }n# t          $ r Y nw xY wt          |t                    r|                    d          nd}d}|rD|                    d          }|dk    r)||dz   d                                         }|d|         }||fS )zGParses the given error response to extract Auth error code and message.r  r   N:rN   )r   rE   r   r  r   findstrip)r   
error_dictparsed_bodyr	  r
  	separators         r"   r  r    s    Jmmook4(( 	6$"55J    )3:t(D(DN:>>)$$$$DN $IIcNN	??!)a-..17799N

#Ds   ?A 
AAc                 ^    |rt          |d          r|j        nd}|rd| nd}| d|  d| S )Nr   z Error while calling Auth service r:   z (z).)hasattrr   )r	  r  r
  r   exts        r"   r  r    sc    cX'899ch..@b "0
8
n


bC.......r$   )F)Tr   );r7   r   r;   rW   urllibr   firebase_adminr   r   r=   r   r   r   r   r   r?   rA   rJ   rS   rZ   r^   rc   rg   rj   rm   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r0   r$   r"   <module>r     s      				 				       % % % % % % ! ! ! ! ! ! 6  #      3QQQRR #" #" #" #" #" #" #" #"L  % % %   	 	 	 	   $               J J J J       .       8       T T T T TJ9 T T TT T T T Tj; T T T	W 	W 	W 	W 	W*"B 	W 	W 	WV V V V VJ$C V V VV V V V V*9 V V VT T T T TJ$A T T TN N N N Nj5 N N NO O O O O
0 O O OO O O O O1 O O OO O O O O*2 O O O@ @ @ @ @J; @ @ @O O O O O!9 O O OV V V V V
7 V V VX X X X X:#D X X XX X X X XJ$E X X X  :./+):#@+8+'#?#@  "D D D$     ,/ / / / /r$   