
    \AhF                     r   S SK r S SKJr  S SKJrJ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JrJrJr  SSKJrJr  \R0                  SS4S jrSS jrS rS rS rS rSS jrSS jr SS jr!SS jr"SS jr#S r$S r%SS jr&g! \ a	    S SKJr   N}f = f! \ a    S SKJ
r
  \
R                  r	 Nf = f)    N)timegm)datetime	timedelta)Mapping)UTC)timezone)jws   )
ALGORITHMS)ExpiredSignatureErrorJWSErrorJWTClaimsErrorJWTError)calculate_at_hashtimedelta_total_secondsc                    S HF  n[        U R                  U5      [        5      (       d  M)  [        X   R	                  5       5      X'   MH     U(       a   [        U[        R                  U   5      U S'   [        R                  " XX2S9$ )a  Encodes a claims set and returns a JWT string.

JWTs are JWS signed objects with a few reserved claims.

Args:
    claims (dict): A claims set to sign
    key (str or dict): The key to use for signing the claim set. Can be
        individual JWK or JWK set.
    algorithm (str, optional): The algorithm to use for signing the
        the claims.  Defaults to HS256.
    headers (dict, optional): A set of headers that will be added to
        the default headers.  Any headers that are added as additional
        headers will override the default headers.
    access_token (str, optional): If present, the 'at_hash' claim will
        be calculated and added to the claims present in the 'claims'
        parameter.

Returns:
    str: The string representation of the header, claims, and signature.

Raises:
    JWTError: If there is an error encoding the claims.

Examples:

    >>> jwt.encode({'a': 'b'}, 'secret', algorithm='HS256')
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'

)expiatnbfat_hash)headers	algorithm)

isinstancegetr   r   utctimetupler   r   HASHESr	   sign)claimskeyr   r   access_token
time_claims         OC:\Users\julio\Documents\inmobiliaria_backend\env\Lib\site-packages\jose/jwt.pyencoder#      so    > ,
fjj,h77!'(:(G(G(I!JF ,
 -lJ<M<Mi<XYy88FFF    c           
      N   0 SS_SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS0EnU(       a  UR                  U5        UR                  SS5      n	 [        R                  " XX)S9n
[        R                  " U 5      S   n [        R                  " U
R                  S5      5      n[        U[        5      (       d  [        S5      e[        UUUUUUUS9  U$ ! [         a  n[        U5      eSnAff = f! [         a  n[        SU-  5      eSnAff = f)a^  Verifies a JWT string's signature and validates reserved claims.

Args:
    token (str): A signed JWS to be verified.
    key (str or iterable): A key to attempt to verify the payload with.
        This can be simple string with an individual key (e.g. "a1234"),
        a tuple or list of keys (e.g. ("a1234...", "b3579"),
        a JSON string, (e.g. '["a1234", "b3579"]'),
        a dict with the 'keys' key that gives a tuple or list of keys (e.g {'keys': [...]} ) or
        a dict or JSON string for a JWK set as defined by RFC 7517 (e.g.
            {'keys': [{'kty': 'oct', 'k': 'YTEyMzQ'}, {'kty': 'oct', 'k':'YjM1Nzk'}]} or
            '{"keys": [{"kty":"oct","k":"YTEyMzQ"},{"kty":"oct","k":"YjM1Nzk"}]}'
        ) in which case the keys must be base64 url safe encoded (with optional padding).
    algorithms (str or list): Valid algorithms that should be used to verify the JWS.
    audience (str): The intended audience of the token.  If the "aud" claim is
        included in the claim set, then the audience must be included and must equal
        the provided claim.
    issuer (str or iterable): Acceptable value(s) for the issuer of the token.
        If the "iss" claim is included in the claim set, then the issuer must be
        given and the claim in the token must be among the acceptable values.
    subject (str): The subject of the token.  If the "sub" claim is
        included in the claim set, then the subject must be included and must equal
        the provided claim.
    access_token (str): An access token string. If the "at_hash" claim is included in the
        claim set, then the access_token must be included, and it must match
        the "at_hash" claim.
    options (dict): A dictionary of options for skipping validation steps.

        defaults = {
            'verify_signature': True,
            'verify_aud': True,
            'verify_iat': True,
            'verify_exp': True,
            'verify_nbf': True,
            'verify_iss': True,
            'verify_sub': True,
            'verify_jti': True,
            'verify_at_hash': True,
            'require_aud': False,
            'require_iat': False,
            'require_exp': False,
            'require_nbf': False,
            'require_iss': False,
            'require_sub': False,
            'require_jti': False,
            'require_at_hash': False,
            'leeway': 0,
        }

Returns:
    dict: The dict representation of the claims set, assuming the signature is valid
        and all requested data validation passes.

Raises:
    JWTError: If the signature is invalid in any way.
    ExpiredSignatureError: If the signature has expired.
    JWTClaimsError: If any claim is invalid in any way.

Examples:

    >>> payload = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'
    >>> jwt.decode(payload, 'secret', algorithms='HS256')

verify_signatureT
verify_aud
verify_iat
verify_exp
verify_nbf
verify_iss
verify_sub
verify_jtiverify_at_hashrequire_audFrequire_iatrequire_exprequire_nbfrequire_issrequire_subrequire_jtirequire_at_hashleewayr   )verifyNalgutf-8zInvalid payload string: %sz-Invalid payload string: must be a json object)audienceissuersubjectr   r    options)updater   r	   r8   r   r   get_unverified_headerjsonloadsdecode
ValueErrorr   r   _validate_claims)tokenr   
algorithmsr>   r;   r<   r=   r    defaultsr&   payloader   r   s                 r"   rC   rC   B   s   DDd 	d 	d	
 	d 	d 	d 	d 	$ 	u 	u 	u 	u 	u 	u  	u!" 	5#$ 	!%H*  ||$6=**UM
 ))%07I9GNN734 fg&&FGG! M1  qk  93a7889s0   %C* %D *
D4C??D
D$DD$c                 f     [         R                  " U 5      nU$ ! [         a    [        S5      ef = f)a  Returns the decoded headers without verification of any kind.

Args:
    token (str): A signed JWT to decode the headers from.

Returns:
    dict: The dict representation of the token headers.

Raises:
    JWTError: If there is an exception decoding the token.
zError decoding token headers.)r	   get_unverified_headers	Exceptionr   )rF   r   s     r"   r@   r@      s;    8,,U3 N  86778s    0c                     [        U 5      $ )aW  Returns the decoded headers without verification of any kind.

This is simply a wrapper of get_unverified_header() for backwards
compatibility.

Args:
    token (str): A signed JWT to decode the headers from.

Returns:
    dict: The dict representation of the token headers.

Raises:
    JWTError: If there is an exception decoding the token.
)r@   )rF   s    r"   rL   rL      s     !''r$   c                 2    [         R                  " U 5      n [        R
                  " UR                  S5      5      n[        U[        5      (       d  [        S5      eU$ ! [         a    [        S5      ef = f! [         a  n[        SU-  5      eSnAff = f)a  Returns the decoded claims without verification of any kind.

Args:
    token (str): A signed JWT to decode the headers from.

Returns:
    dict: The dict representation of the token claims.

Raises:
    JWTError: If there is an exception decoding the token.
zError decoding token claims.r:   zInvalid claims string: %sNz,Invalid claims string: must be a json object)
r	   get_unverified_claimsrM   r   rA   rB   rC   rD   r   r   )rF   r   rJ   s      r"   rP   rP      s    7**518FMM'23 fg&&EFFM  75667
  82Q6778s"   A  %A9  A69
BBBc                 b    SU ;  a  g [        U S   5        g! [         a    [        S5      ef = f)aI  Validates that the 'iat' claim is valid.

The "iat" (issued at) claim identifies the time at which the JWT was
issued.  This claim can be used to determine the age of the JWT.  Its
value MUST be a number containing a NumericDate value.  Use of this
claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
r   Nz)Issued At claim (iat) must be an integer.)intrD   r   r   s    r"   _validate_iatrT      s>     FJF5M JHIIJs    .c                     SU ;  a  g [        U S   5      n[        [        R
                  " [        5      R                  5       5      nX#U-   :  a  [        S5      eg! [         a    [        S5      ef = f)at  Validates that the 'nbf' claim is valid.

The "nbf" (not before) claim identifies the time before which the JWT
MUST NOT be accepted for processing.  The processing of the "nbf"
claim requires that the current date/time MUST be after or equal to
the not-before date/time listed in the "nbf" claim.  Implementers MAY
provide for some small leeway, usually no more than a few minutes, to
account for clock skew.  Its value MUST be a number containing a
NumericDate value.  Use of this claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
    leeway (int): The number of seconds of skew that is allowed.
r   Nz*Not Before claim (nbf) must be an integer.z The token is not yet valid (nbf))rR   rD   r   r   r   nowr   r   )r   r7   r   rV   s       r"   _validate_nbfrW     s{      FK&-  c"//1
2C
Fl?@@   KIJJK   A A2c                     SU ;  a  g [        U S   5      n[        [        R
                  " [        5      R                  5       5      nX#U-
  :  a  [        S5      eg! [         a    [        S5      ef = f)a}  Validates that the 'exp' claim is valid.

The "exp" (expiration time) claim identifies the expiration time on
or after which the JWT MUST NOT be accepted for processing.  The
processing of the "exp" claim requires that the current date/time
MUST be before the expiration date/time listed in the "exp" claim.
Implementers MAY provide for some small leeway, usually no more than
a few minutes, to account for clock skew.  Its value MUST be a number
containing a NumericDate value.  Use of this claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
    leeway (int): The number of seconds of skew that is allowed.
r   Nz/Expiration Time claim (exp) must be an integer.zSignature has expired.)	rR   rD   r   r   r   rV   r   r   r   )r   r7   r   rV   s       r"   _validate_exprZ   0  s{      FP&-  c"//1
2C
Fl#$<==   PNOOPrX   c                     SU ;  a  gU S   n[        U[        5      (       a  U/n[        U[        5      (       d  [        S5      e[	        S U 5       5      (       a  [        S5      eX;  a  [        S5      eg)a^  Validates that the 'aud' claim is valid.

The "aud" (audience) claim identifies the recipients that the JWT is
intended for.  Each principal intended to process the JWT MUST
identify itself with a value in the audience claim.  If the principal
processing the claim does not identify itself with a value in the
"aud" claim when this claim is present, then the JWT MUST be
rejected.  In the general case, the "aud" value is an array of case-
sensitive strings, each containing a StringOrURI value.  In the
special case when the JWT has one audience, the "aud" value MAY be a
single case-sensitive string containing a StringOrURI value.  The
interpretation of audience values is generally application specific.
Use of this claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
    audience (str): The audience that is verifying the token.
audNzInvalid claim format in tokenc              3   L   #    U  H  n[        U[        5      (       + v   M     g 7fN)r   str).0cs     r"   	<genexpr> _validate_aud.<locals>.<genexpr>l  s     
;?az!S!!!?s   "$zInvalid audience)r   r_   listr   any)r   r;   audience_claimss      r"   _validate_audrg   N  s|    ( F 	UmO/3''*+ot,,<==

;?
;;;<==&/00 'r$   c                 |    Ub9  [        U[        5      (       a  U4nU R                  S5      U;  a  [        S5      egg)a  Validates that the 'iss' claim is valid.

The "iss" (issuer) claim identifies the principal that issued the
JWT.  The processing of this claim is generally application specific.
The "iss" value is a case-sensitive string containing a StringOrURI
value.  Use of this claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
    issuer (str or iterable): Acceptable value(s) for the issuer that
                              signed the token.
NisszInvalid issuer)r   r_   r   r   )r   r<   s     r"   _validate_issrj   r  sE     fc""YF::eF* !122 + r$   c                     SU ;  a  g[        U S   [        5      (       d  [        S5      eUb!  U R                  S5      U:w  a  [        S5      egg)aC  Validates that the 'sub' claim is valid.

The "sub" (subject) claim identifies the principal that is the
subject of the JWT.  The claims in a JWT are normally statements
about the subject.  The subject value MUST either be scoped to be
locally unique in the context of the issuer or be globally unique.
The processing of this claim is generally application specific.  The
"sub" value is a case-sensitive string containing a StringOrURI
value.  Use of this claim is OPTIONAL.

Arg
    claims (dict): The claims dictionary to validate.
    subject (str): The subject of the token.
subNzSubject must be a string.zInvalid subject)r   r_   r   r   )r   r=   s     r"   _validate_subrm     sY      FfUmS))899::e' !233 ( r$   c                 X    SU ;  a  g[        U S   [        5      (       d  [        S5      eg)al  Validates that the 'jti' claim is valid.

The "jti" (JWT ID) claim provides a unique identifier for the JWT.
The identifier value MUST be assigned in a manner that ensures that
there is a negligible probability that the same value will be
accidentally assigned to a different data object; if the application
uses multiple issuers, collisions MUST be prevented among values
produced by different issuers as well.  The "jti" claim can be used
to prevent the JWT from being replayed.  The "jti" value is a case-
sensitive string.  Use of this claim is OPTIONAL.

Args:
    claims (dict): The claims dictionary to validate.
jtiNzJWT ID must be a string.)r   r_   r   rS   s    r"   _validate_jtirp     s1     FfUmS))788 *r$   c                     SU ;  a  gU(       d  Sn[        U5      e [        U[        R                  U   5      nU S   U:w  a  [        S5      eg! [        [
        4 a    Sn[        U5      ef = f)a  
Validates that the 'at_hash' is valid.

Its value is the base64url encoding of the left-most half of the hash
of the octets of the ASCII representation of the access_token value,
where the hash algorithm used is the hash algorithm used in the alg
Header Parameter of the ID Token's JOSE Header. For instance, if the
alg is RS256, hash the access_token value with SHA-256, then take the
left-most 128 bits and base64url encode them. The at_hash value is a
case sensitive string.  Use of this claim is OPTIONAL.

Args:
  claims (dict): The claims dictionary to validate.
  access_token (str): The access token returned by the OpenID Provider.
  algorithm (str): The algorithm used to sign the JWT, as specified by
      the token headers.
r   Nz:No access_token provided to compare against at_hash claim.z;Unable to calculate at_hash to verify against token claims.z*at_hash claim does not match access_token.)r   r   r   r   	TypeErrorrD   )r   r    r   msgexpected_hashs        r"   _validate_at_hashru     s    $ JS!!"),
8I8I)8TU
 iM)IJJ *	 z" "KS!!"s   A A-c                    UR                  SS5      n[        U[        5      (       a  [        U5      nUR	                  5        Vs/ s H3  oR                  S5      (       d  M  Xh   (       d  M%  U[        S5      S  PM5     n	nU	 H  n
X;  a  [        SU
-  5      eSUSU
-   '   M      [        U[        4[        S 5      45      (       d  [        S5      eUR                  S5      (       a  [        U 5        UR                  S	5      (       a	  [        XS
9  UR                  S5      (       a	  [        XS
9  UR                  S5      (       a	  [        XS9  UR                  S5      (       a	  [        XS9  UR                  S5      (       a	  [        XS9  UR                  S5      (       a  [!        U 5        UR                  S5      (       a  [#        XU5        g g s  snf )Nr7   r   require_z&missing required key "%s" among claimsTverify_z!audience must be a string or Noner(   r*   )r7   r)   r'   )r;   r+   )r<   r,   )r=   r-   r.   )r   r   r   r   keys
startswithlenr   r_   typerT   rW   rZ   rg   rj   rm   rp   ru   )r   r;   r<   r=   r   r    r>   r7   rJ   required_claimsrequire_claims              r"   rE   rE     s   [[1%F&)$$(05<\\^o^||T^G_+dkdn+qZ*+^Oo(&CmSTT15GI-.	 ) h#d 455:;;{{<  f{{<  f,{{<  f,{{<  f0{{<  f,{{<  f.{{<  f{{#$$&	: %? ps   G"G-G)NNNNNN)r   r^   )'rA   calendarr   r   r   collections.abcr   ImportErrorcollectionsr   r   utcjoser	   	constantsr   
exceptionsr   r   r   r   utilsr   r   HS256r#   rC   r@   rL   rP   rT   rW   rZ   rg   rj   rm   rp   ru   rE    r$   r"   <module>r      s      ($'  ! Q Q = #-"2"2Dt 'GTvr(($8J*A<><!1H3*469, KF%;i  $#$
  !
,,Cs"   B	 B 	BBB65B6