Ë
    OK¸iX  ã                   óÄ   — d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ  e j"                  e«      Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Z	 dd„Zy)é    N)Úurlsafe_b64decodeÚurlsafe_b64encode)Úsha256©Úparse_http_listÚparse_keqv_list)Úsettings)ÚImproperlyConfigured)Úforce_bytesc                 ó.   — t        | «      }t        |«      S )zb
    Convert a WWW-Authentication header into a dict that can be used
    in a JSON response.
    r   )ÚheaderÚitemss     úP/var/www/aura-ras/venv/lib/python3.12/site-packages/mozilla_django_oidc/utils.pyÚparse_www_authenticate_headerr      s   € ô
 ˜FÓ#€EÜ˜5Ó!Ð!ó    c                 óž   — 	 |rt        t        | |d   «      S t        t        | «      S # t        $ r t        dj	                  | «      «      ‚w xY w)z`
    Load an attribute from the django settings.

    :raises:
        ImproperlyConfigured
    r   zSetting {0} not found)Úgetattrr	   ÚAttributeErrorr
   Úformat)ÚattrÚargss     r   Úimport_from_settingsr      sS   € ðIÙÜœ8 T¨4°©7Ó3Ð3Ü”x Ó&Ð&øÜò IÜ"Ð#:×#AÑ#AÀ$Ó#GÓHÐHðIús   ‚( ˜( ¨$Ac                 ó$   — | j                  |«      S )z"Return the absolute URL of a path.)Úbuild_absolute_uri)ÚrequestÚpaths     r   Ú
absolutifyr   '   s   € à×%Ñ% dÓ+Ð+r   c                 óR   — d}t        j                  |t        «       | j                  S )aT  return True if the user is authenticated.
    This is necessary because in Django 1.10 the `user.is_authenticated`
    stopped being a method and is now a property.
    Actually `user.is_authenticated()` actually works, thanks to a backwards
    compat trick in Django. But in Django 2.0 it will cease to work
    as a callable method.
    zH`is_authenticated()` is going to be removed in mozilla-django-oidc v 2.x)ÚwarningsÚwarnÚDeprecationWarningÚis_authenticated)ÚuserÚmsgs     r   r"   r"   ,   s%   € ð U€CÜ‡M�M�#Ô)Ô*Ø× Ñ Ð r   c                 ón   — t        t        | «      «      j                  d«      }|j                  d«      }|S )a  Return a URL-Safe, base64 encoded version of bytes_like_obj
    Implements base64urlencode as described in
    https://datatracker.ietf.org/doc/html/rfc7636#appendix-A
    This function is not used by the OpenID client; it's just for testing PKCE related functions.
    úutf-8ú=)r   r   ÚdecodeÚrstrip)Úbytes_like_objÚss     r   Úbase64_url_encoder,   :   s0   € ô 	œ+ nÓ5Ó6×=Ñ=¸gÓF€AØ	�‰�‹€AØ€Hr   c                 ó¢   — | }t        |«      dz  }|dk(  r|dz  }n|dk(  r|dz  }n|dk7  rt        d«      ‚t        |j                  d«      «      S )	a  Return the bytes encoded in a URL-Safe, base64 encoded string.
    Implements inverse of base64urlencode as described in
    https://datatracker.ietf.org/doc/html/rfc7636#appendix-A
    This function is not used by the OpenID client; it's just for testing PKCE related functions.
    é   é   z==é   r'   r   zInvalid base64 stringr&   )ÚlenÚ
ValueErrorr   Úencode)Ústring_like_objr+   Úsizes      r   Úbase64_url_decoder6   E   s]   € ð 	€Aäˆq‹6�A‰:€DØˆq‚yØ	ˆT‰	‰Ø	�ŠØ	ˆS‰‰Ø	�ŠÜÐ0Ó1Ð1Ü˜QŸX™X gÓ.Ó/Ð/r   c                 ó’   — |dk(  r| S |dk(  r1t        t        | j                  d«      «      j                  «       «      S t	        d«      ‚)al  Return a code_challege, which proves knowledge of the code_verifier.
    The code challenge is generated according to method which must be one
    of the methods defined in https://datatracker.ietf.org/doc/html/rfc7636#section-4.2:
    - plain:
    code_challenge = code_verifier
    - S256:
    code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
    ÚplainÚS256Úasciiz0code challenge method must be 'plain' or 'S256'.)r,   r   r3   Údigestr2   )Úcode_verifierÚmethods     r   Úgenerate_code_challenger>   W   sL   € ð �ÒØÐà	�6Ò	Ü ¤¨×(<Ñ(<¸WÓ(EÓ!F×!MÑ!MÓ!OÓPÐPô ÐKÓLÐLr   c                 óP  — |j                  d«      }d|v |duk(  sJ ‚d| j                  vst        | j                  d   t        «      si | j                  d<   t	        dd«      }t        | j                  d   «      |k\  r�t        j                  dj                  |«      «       d}t        j                  «       }| j                  d   j                  «       D ]  \  }}	|	d   |k  sŒ|}|	d   }Œ |r| j                  d   |= ||t        j                  «       d	œ| j                  d   |<   y)
aî  
    Stores the `state` and `nonce` parameters and an optional `code_verifier` (for PKCE) in a
    session dictionary which maps `state` -> {nonce, code_verifier}.  Each entry includes
    the time when it was added. The dictionary can contain multiple state -> {nonce, code_verifier}
    mappings to allow parallel logins with multiple browser sessions.
    To keep the session space to a reasonable size, the dictionary is kept at 50
    state -> {nonce, code_verifier} mappings maximum.
    ÚnonceÚcode_challengeNÚoidc_statesÚOIDC_MAX_STATESé2   zLUser has more than {} "oidc_states" in his session, deleting the oldest one!Úadded_on)r<   r@   rE   )ÚgetÚsessionÚ
isinstanceÚdictr   r1   ÚLOGGERÚinfor   Útimer   )
r   ÚstateÚparamsr<   r@   ÚlimitÚoldest_stateÚoldest_added_onÚ
item_stateÚitems
             r   Ú+add_state_and_verifier_and_nonce_to_sessionrT   k   s.  € ð �J‰J�wÓ€Eð  Ð&¨MÀÐ,EÒFÐFÐFð ˜GŸO™OÑ+´:Ø�‰˜Ñ&¬ô4ð *,ˆ�‰˜Ñ&ô !Ð!2°BÓ7€EÜ
ˆ7�?‰?˜=Ñ)Ó*¨eÒ3Ü�‰ð'ß'-¡v¨e£}ô	
ð ˆÜŸ)™)›+ˆØ '§¡°Ñ >× DÑ DÓ Fò 	3ÑˆJ˜Ø�JÑ /Ó1Ø)�Ø"& zÑ"2‘ð	3ñ Ø—‘ Ñ.¨|Ð<ð 'ØÜ—I‘I“Kñ-€G‡O�O�MÑ" 5Ò)r   )N)ÚloggingrL   r   Úbase64r   r   Úhashlibr   Úurllib.requestr   r   Údjango.confr	   Údjango.core.exceptionsr
   Údjango.utils.encodingr   Ú	getLoggerÚ__name__rJ   r   r   r   r"   r,   r6   r>   rT   © r   r   ú<module>r_      sa   ðÛ Û Û ß 7Ý ß ;å  Ý 7Ý -à	ˆ×	Ñ	˜8Ó	$€ò"òIò,ò
!òò0ò$Mð* +/ô5r   