Ë
    ¹ÿj^#  ã                  ó  — d Z ddlmZ ddlmZmZmZ ddlZddlmZm	Z	m
Z
mZmZmZ ddlmZmZmZ dZdZd	Zd
Zd„ Zddd„Z G d„ de«      Z G d„ d«      Z G d„ d«      Z G d„ d«      Z G d„ dej:                  «      Z G d„ de«      Zy)z™Firebase Phone Number Verification module.

This module contains functions for verifying JWTs related to the Firebase
Phone Number Verification service.
é    )Úannotations)ÚAnyÚDictÚOptionalN)ÚPyJWKClientÚInvalidSignatureErrorÚPyJWKClientErrorÚInvalidAudienceErrorÚInvalidIssuerErrorÚExpiredSignatureError)ÚAppÚ_utilsÚ
exceptionsÚ_phone_number_verificationz'https://fpnv.googleapis.com/v1beta/jwksz%https://fpnv.googleapis.com/projects/ÚES256c                ó@   — t        j                  | t        t        «      S ©N)r   Úget_app_serviceÚ_FPNV_ATTRIBUTEÚ_FpnvService)Úapps    úb/root/telegram-saas/.venv/lib/python3.12/site-packages/firebase_admin/phone_number_verification.pyÚ_get_fpnv_servicer   %   s   € Ü×!Ñ! #¤¼ÓEÐEó    ÚPhoneNumberVerificationTokenc                ó6   — t        |«      j                  | «      S )aÌ  Verifies a Firebase Phone Number Verification token.

    Args:
        token: A string containing the Firebase Phone Number Verification JWT.
        app: An App instance (optional).

    Returns:
        PhoneNumberVerificationToken: The verified token claims.

    Raises:
        ValueError: If the token is not a string or is empty.
        InvalidTokenError: If the token is invalid or malformed.
        ExpiredTokenError: If the token has expired.
    )r   Úverify_token)Útokenr   s     r   r   r   (   s   € ô ˜SÓ!×.Ñ.¨uÓ5Ð5r   c                  óž   ‡ — e Zd ZdZˆ f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	„ «       Zˆ xZS )r   zÕRepresents a verified Firebase Phone Number Verification token.

    This class behaves like a dictionary, allowing access to the decoded claims.
    It also provides convenience properties for common claims.
    c                óL   •— t         ‰| �  |«       |j                  d«      | d<   y )NÚsubÚphone_number)ÚsuperÚ__init__Úget)ÚselfÚclaimsÚ	__class__s     €r   r$   z%PhoneNumberVerificationToken.__init__A   s#   ø€ Ü‰Ñ˜Ô Ø%Ÿz™z¨%Ó0ˆˆ^Òr   c                ó$   — | j                  d«      S )zfReturns the phone number of the user.
        This corresponds to the 'sub' claim in the JWT.
        r!   ©r%   ©r&   s    r   r"   z)PhoneNumberVerificationToken.phone_numberE   s   € ð
 �x‰x˜‹Ðr   c                ó$   — | j                  d«      S )z=Returns the issuer identifier for the issuer of the response.Úissr*   r+   s    r   Úissuerz#PhoneNumberVerificationToken.issuerL   ó   € ð �x‰x˜‹Ðr   c                ó$   — | j                  d«      S )z6Returns the audience for which this token is intended.Úaudr*   r+   s    r   Úaudiencez%PhoneNumberVerificationToken.audienceQ   r/   r   c                ó$   — | j                  d«      S )z1Returns the expiration time since the Unix epoch.Úexpr*   r+   s    r   r4   z PhoneNumberVerificationToken.expV   r/   r   c                ó$   — | j                  d«      S )z0Returns the issued-at time since the Unix epoch.Úiatr*   r+   s    r   r6   z PhoneNumberVerificationToken.iat[   r/   r   c                ó$   — | j                  d«      S )zBReturns the sub (subject) of the token, which is the phone number.r!   r*   r+   s    r   r!   z PhoneNumberVerificationToken.sub`   r/   r   c                ó   — | S )z!Returns the entire map of claims.© r+   s    r   r'   z#PhoneNumberVerificationToken.claimse   s	   € ð ˆr   )ÚreturnÚstr)r:   Úint)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   Úpropertyr"   r.   r2   r4   r6   r!   r'   Ú__classcell__)r(   s   @r   r   r   :   s™   ø„ ñô1ð òó ðð òó ðð òó ðð òó ðð òó ðð òó ðð ñó ôr   c                  ó"   — e Zd ZdZdZd„ Zdd„Zy)r   zOService class that implements Firebase Phone Number Verification functionality.Nc                óˆ   — |j                   | _        | j                  st        d«      ‚t        | j                  «      | _        y )Nz‘Project ID is required for Firebase Phone Number Verification. Please ensure the app is initialized with a credential that contains a project ID.)Ú
project_idÚ_project_idÚ
ValueErrorÚ_FpnvTokenVerifierÚ	_verifier)r&   r   s     r   r$   z_FpnvService.__init__o   s>   € ØŸ>™>ˆÔØ×ÒÜðSóð ô
 ,¨D×,<Ñ,<Ó=ˆ�r   c                óJ   — t        | j                  j                  |«      «      S )a  Verifies a Firebase Phone Number Verification token.

        Verifies the signature, expiration, and claims of the token.

        Args:
            token: A string containing the Firebase Phone Number Verification JWT.

        Returns:
            PhoneNumberVerificationToken: The verified token claims.

        Raises:
            ValueError: If the token is not a string or is empty.
            InvalidTokenError: If the token is invalid or malformed.
            ExpiredTokenError: If the token has expired.
        )r   rI   Úverify)r&   r   s     r   r   z_FpnvService.verify_tokeny   s   € ô  ,¨D¯N©N×,AÑ,AÀ%Ó,HÓIÐIr   )r:   r   )r=   r>   r?   r@   rF   r$   r   r9   r   r   r   r   k   s   „ ÙYØ€Kò>ôJr   r   c                  ó6   — e Zd ZdZdZdZd„ Zdd„Zdd„Zdd„Z	y)	rH   zWInternal class for verifying Firebase Phone Number Verification JWTs signed with ES256.Nc                ó>   — || _         t        t        d¬«      | _        y )Ni`T  )Úlifespan)rF   r   Ú_FPNV_JWKS_URLÚ_jwks_client)r&   rE   s     r   r$   z_FpnvTokenVerifier.__init__‘   s   € Ø%ˆÔÜ'¬ÀÔGˆÕr   c           
     ó`  — t         j                  d|«       	 | j                  t        j                  |«      «       | j
                  j                  |«      }| j                  ||j                  «      }|S # t        j                  t        f$ r}t        d|t        |dd«      ¬«      |‚d}~ww xY w)z<Verifies the given Firebase Phone Number Verification token.z.Firebase Phone Number Verification check tokenz1Verifying phone number verification token failed.Úhttp_responseN)ÚcauserR   )Ú_ValidatorsÚcheck_stringÚ_validate_headersÚjwtÚget_unverified_headerrP   Úget_signing_key_from_jwtÚ_decode_and_verifyÚkeyÚInvalidTokenErrorr	   Úgetattr)r&   r   Úsigning_keyr'   Ú	exceptions        r   rK   z_FpnvTokenVerifier.verify•   s§   € ä× Ñ Ð!QÐSXÔYð		Ø×"Ñ"¤3×#<Ñ#<¸UÓ#CÔDØ×+Ñ+×DÑDÀUÓKˆKØ×,Ñ,¨U°K·O±OÓDˆFð ˆøô ×%Ñ%Ô'7Ð8ò 	Ü#ØCØÜ% i°À$ÓGôð ð	ûð	ús   ˜AA5 Á5B-ÂB(Â(B-c                ó   — |j                  d«      €t        d«      ‚|j                  d«      dk7  rt        d|j                  d«      ›d�«      ‚|j                  d«      }|t        k7  rt        d	t        › d
|› d�«      ‚y)zValidates the headers.ÚkidNzToken has no 'kid' claim.ÚtypÚJWTzHThe provided token has an incorrect type header. Expected 'JWT' but got ú.Úalgz9The provided token has an incorrect alg header. Expected z	 but got )r%   r\   Ú_ALGORITHM_ES256)r&   ÚheadersÚ	algorithms      r   rV   z$_FpnvTokenVerifier._validate_headers¥   s›   € à�;‰;�uÓÐ%Ü#Ð$?Ó@Ð@à�;‰;�uÓ Ò&Ü#ð*Ø*1¯+©+°eÓ*<Ð)?¸qðBóð ð
 —K‘K Ó&ˆ	ØÔ(Ò(Ü#ðÜ,Ð-¨Y°y°kÀðDóð ð )r   c                óî  — t         › | j                  › �}	 t        j                  ||t        g||¬«      }|j                  d	«      }t        |t        «      r|st        d
«      ‚|S # t
        $ r}t        d«      |‚d}~wt        $ r}t        d|› d�«      |‚d}~wt        $ r}t        d|› d�«      |‚d}~wt        $ r}t        d«      |‚d}~wt        j                  $ r}t        d|› �«      |‚d}~ww xY w)zDecodes and verifies the token.)Ú
algorithmsr2   r.   z,The provided token has an invalid signature.NzEThe provided token has an incorrect "aud" (audience) claim. Expected rd   zCThe provided token has an incorrect "iss" (issuer) claim. Expected zThe provided token has expired.zDecoding token failed. Error: r!   zWThe provided token has an incorrect "sub" (subject) claim. Expected a non-empty string.)Ú_FPNV_ISSUERrF   rW   Údecoderf   r   r\   r
   r   r   ÚExpiredTokenErrorr%   Ú
isinstancer;   )r&   r   r^   Úexpected_issuerÚpayloadr_   Ú	sub_claims          r   rZ   z%_FpnvTokenVerifier._decode_and_verify·   s=  € ä)˜N¨4×+;Ñ+;Ð*<Ð=ˆð	Ü—j‘jØØÜ,Ð-Ø(Ø&ôˆGð< —K‘K Ó&ˆ	Ü˜)¤SÔ)±Ü#ð/óð ð
 ˆøô= %ò 	Ü#Ø>óàðûô $ò 	Ü#ðØ+Ð,¨Að/óð ðûô "ò 	Ü#ðØ+Ð,¨Að/óð ðûô %ò 	Ü#Ø1óàðûô ×$Ñ$ò 	Ü#Ø0°°Ð<óàðûð	úsG   –A% Á%	C4Á.A:Á:C4ÂBÂC4Â"B2Â2C4Â>C
Ã
C4Ã C/Ã/C4)r:   zDict[str, Any])rg   r   r:   ÚNone)
r=   r>   r?   r@   rP   rF   r$   rK   rV   rZ   r9   r   r   rH   rH   Œ   s$   „ ÙaØ€LØ€KòHóó ô$)r   rH   c                  ó"   — e Zd ZdZedd„«       Zy)rT   z‚A collection of data validation utilities.

    Methods provided in this class raise ``ValueErrors`` if any validations fail.
    c                óD   — t        |t        «      r|st        |› d�«      ‚y)z&Checks if the given value is a string.z must be a non-empty string.N)rn   r;   rG   )ÚclsÚlabelÚvalues      r   rU   z_Validators.check_stringé   s(   € ô ˜%¤Ô%©UÜ ˜wÐ&BÐCÓDÐDð .3r   N)rv   r;   rw   r   )r=   r>   r?   r@   ÚclassmethodrU   r9   r   r   rT   rT   ã   s   „ ñð
 òEó ñEr   rT   c                  ó   — e Zd ZdZdd„Zy)r\   zBRaised when a Firebase Phone Number Verification token is invalid.Nc                óH   — t         j                  j                  | |||«       y r   )r   ÚInvalidArgumentErrorr$   ©r&   ÚmessagerS   rR   s       r   r$   zInvalidTokenError.__init__ó   s   € Ü×'Ñ'×0Ñ0°°wÀÀ}ÕUr   ©NN©r=   r>   r?   r@   r$   r9   r   r   r\   r\   ð   s   „ ÙLôVr   r\   c                  ó   — e Zd ZdZdd„Zy)rm   zBRaised when a Firebase Phone Number Verification token is expired.Nc                ó4   — t         j                  | |||«       y r   )r\   r$   r|   s       r   r$   zExpiredTokenError.__init__ù   s   € Ü×"Ñ" 4¨°%¸ÕGr   r~   r   r9   r   r   rm   rm   ö   s   „ ÙLôHr   rm   r   )r   r;   r   zOptional[App]r:   r   ) r@   Ú
__future__r   Útypingr   r   r   rW   r   r   r	   r
   r   r   Úfirebase_adminr   r   r   r   rO   rk   rf   r   r   Údictr   r   rH   rT   r{   r\   rm   r9   r   r   ú<module>r†      s    ðñõ
 #ß &Ñ &ã 
÷÷ ÷
 3Ñ 2à.€Ø:€Ø6€ØÐ òFô6ô$. 4ô .÷bJñ J÷BTñ T÷n
Eñ 
EôV˜
×7Ñ7ô VôHÐ)õ Hr   