
    /_i!                        d dl mZ d dlmZ d dlmZmZmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ er G d d	e
      Z G d
 d      ZddZddZddZddZddZddZddZy)    )annotations)Mapping)datetime	timedeltatimezone)TYPE_CHECKINGAny	TypedDictcast)config)StreamlitAuthError)AttrDictsecrets_singletonc                  "    e Zd ZU ded<   ded<   y)ProviderTokenPayloadstrproviderintexpN)__name__
__module____qualname____annotations__     R/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/auth_util.pyr   r      s    r   r   c                  :    e Zd ZdZddZd	dZd
ddZddZddZy)	AuthCachezBSimple cache implementation for storing info required for Authlib.c                    i | _         y Ncacheselfs    r   __init__zAuthCache.__init__#   s	    %'
r   c                8    | j                   j                  |      S r    )r"   getr$   keys     r   r'   zAuthCache.get&   s    zz~~c""r   Nc                "    || j                   |<   y r    r!   )r$   r)   value
expires_ins       r   setzAuthCache.set+   s    

3r   c                    | j                   S r    r!   r#   s    r   get_dictzAuthCache.get_dict.   s    zzr   c                <    | j                   j                  |d        y r    )r"   popr(   s     r   deletezAuthCache.delete1   s    

sD!r   )returnNone)r)   r   r3   r	   r    )r)   r   r+   r	   r,   z
int | Noner3   r4   )r3   dict[str, Any])r)   r   r3   r4   )	r   r   r   __doc__r%   r'   r-   r/   r2   r   r   r   r   r       s    L(#
 "r   r   c                     	 ddl } | j                  }t        t        t        |j                  d                  }|dk  ry	 y# t        t        f$ r Y yw xY w)zCheck if Authlib is installed.r   N.)         FT)authlib__version__tuplemapr   splitImportErrorModuleNotFoundError)r<   authlib_versionauthlib_version_tuples      r   is_authlib_installedrE   5   sa    	!-- %c#/D/DS/I&J K 9, -  ,- s   =A AAc                     t        j                  d      } t        j                         r)t        j                  d      }|r|j	                  d|       } | S )zEGet the cookie signing secret from the configuration or secrets.toml.zserver.cookieSecretauthcookie_secret)r   
get_optionr   load_if_toml_existsr'   )signing_secretauth_sections     r   get_signing_secretrM   D   sJ     ++,ABN,,.(,,V4)--o~NNr   c                     t        i       } 	 t        j                         rt        dt        j                  d            } | S )Nr   rG   )r   r   rJ   r   r'   )rL   s    r   get_secrets_auth_sectionrO   N   s8    B<L5,,.J(9(=(=f(EFr   c                   	 ddl m} ddi}| t	        j
                  t        j                        t        d      z   d	}|j                  ||t                     }|j                  d
      S # t        $ r t        d      dw xY w)zAReturns a signed JWT token with the provider and expiration time.r   )jwtcTo use authentication features, you need to install Authlib>=1.3.2, e.g. via `pip install Authlib`.NalgHS256r;   )minutes)r   r   zlatin-1)authlib.joserQ   rA   r   r   nowr   utcr   encoderM   decode)r   rQ   headerpayloadprovider_tokens        r   encode_provider_tokenr^   W   s    $ WF||HLL)Ia,@@G  JJvw8J8LMN  ++   u
	s   A+ +Bc                   	 ddl m}m}m} ddiddid}	 |j                  | t               |      }|j                          t        d
|      S # t        $ r t        d      dw xY w# |$ r}t        d	|       dd}~ww xY w)z-Decode the JWT token and validate the claims.r   )	JoseError	JWTClaimsrQ   rR   N	essentialT)r   r   )claims_optionszError decoding provider token: r   )
rV   r`   ra   rQ   rA   r   rZ   rM   validater   )r]   r`   ra   rQ   claim_optionsr\   es          r   decode_provider_tokenrg   j   s    :: )$/k4=PQMR ZZ.0 ( 
 	 &00!   u
	  R #B1#!FGTQRs"   
A ,A' A$'B ,A;;B c           	     v   i }| j                  d      r| j                  d      |d<   | j                  d      r| j                  d      |d<   | j                  d      r| j                  d      |d<   | j                  d      r6t        d| j                  dt        i                   j                         |d<   |S )zKGenerate a default provider section for the 'auth' section of secrets.toml.	client_idclient_secretserver_metadata_urlclient_kwargsr   )r'   r   r   to_dict)rL   default_provider_sections     r   !generate_default_provider_sectionro      s    !$0<0@0@0M -(4@4D4D_4U 1-.:F:J:J!;
 !67 (48(((2,G5

') 	!1 $#r   c                8   t        j                         st        d      t        j                  d      }|t        d      d|vrt        d      d|vrt        d      |j                  |       }d| v rt        d	|  d
      || dk(  rt	        |      }|| dk(  rt        d      t        d|  d      t        |t              st        d|  d      g d}|D cg c]	  }||vs| }}|r&| dk(  rt        d| d      t        d|  d| d      yc c}w )z[Validate the general auth credentials and auth credentials for the given
    provider.
    zTo use authentication features you need to configure credentials for at
            least one authentication provider in `.streamlit/secrets.toml`.rG   Nredirect_urizAuthentication credentials in `.streamlit/secrets.toml` are missing the
            "redirect_uri" key. Please check your configuration.rH   zAuthentication credentials in `.streamlit/secrets.toml` are missing the
            "cookie_secret" key. Please check your configuration._zAuth provider name "zI" contains an underscore. Please use a provider name without underscores.defaultzAuthentication credentials in `.streamlit/secrets.toml` are missing for
                the default authentication provider. Please check your configuration.zeAuthentication credentials in `.streamlit/secrets.toml` are missing for the authentication provider "z#". Please check your configuration.zYAuthentication credentials in `.streamlit/secrets.toml` for the authentication provider "z6" must be valid TOML. Please check your configuration.)ri   rj   rk   zAuthentication credentials in `.streamlit/secrets.toml` for the default authentication provider are missing the following keys: z". Please check your configuration.z"" are missing the following keys: )r   rJ   r   r'   ro   
isinstancer   )r   rL   provider_sectionrequired_keysr)   missing_keyss         r   validate_auth_credentialsrx      s    002 O
 	

 %((0L O
 	
 \) D
 	
 l* E
 	

 $''1 h "8* -> ?
 	

 H	$9<\Jy $Y  !,,4: 6
 	
 &0 ((0z 2"#
 	
 JM#0PCC?O4OCPLPy $S. BD 
 !((0z1Sn>@
 	
  Qs   	D(DN)r3   bool)r3   r   )r3   r   )r   r   r3   r   )r]   r   r3   r   )rL   r   r3   r5   )r   r   r3   r4   )
__future__r   collections.abcr   r   r   r   typingr   r	   r
   r   	streamlitr   streamlit.errorsr   streamlit.runtime.secretsr   r   r   r   rE   rM   rO   r^   rg   ro   rx   r   r   r   <module>r      s_    # # 2 2 6 6  / Ay 
" "*,&1.$$H
r   