L i!ddlmZddlmZddlmZmZmZddlmZm Z m Z m Z ddl m Z ddlmZddlmZmZer Gdd e ZGd d Zdd Zdd ZddZddZddZddZddZy)) annotations)Mapping)datetime timedeltatimezone) TYPE_CHECKINGAny TypedDictcast)config)StreamlitAuthError)AttrDictsecrets_singletonc"eZdZUded<ded<y)ProviderTokenPayloadstrproviderintexpN)__name__ __module__ __qualname____annotations__Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/auth_util.pyrrs  rrc:eZdZdZddZd dZd d dZd dZd dZy) AuthCachezBSimple cache implementation for storing info required for Authlib.ci|_yNcacheselfs r__init__zAuthCache.__init__#s %' rc8|jj|Sr )r"getr$keys rr'z AuthCache.get&szz~~c""rNc"||j|<yr r!)r$r)value expires_ins rsetz AuthCache.set+s 3rc|jSr r!r#s rget_dictzAuthCache.get_dict.s zzrc<|jj|dyr )r"popr(s rdeletezAuthCache.delete1s sD!r)returnNone)r)rr3r r )r)rr+r r,z int | Noner3r4)r3dict[str, Any])r)rr3r4) rrr__doc__r%r'r-r/r2rrrrr sL(#  "rrc ddl}|j}ttt|j d}|dkry y#t tf$rYywxYw)zCheck if Authlib is installed.rN.)FT)authlib __version__tuplemaprsplit ImportErrorModuleNotFoundError)r<authlib_versionauthlib_version_tuples ris_authlib_installedrE5sa !-- %c#/D/DS/I&J K 9 , -  , -s=AAActjd}tjr)tjd}|r|j d|}|S)zEGet the cookie signing secret from the configuration or secrets.toml.zserver.cookieSecretauth cookie_secret)r get_optionrload_if_toml_existsr')signing_secret auth_sections rget_signing_secretrMDsJ ++,ABN,,.(,,V4 )--o~NN rcti} tjrtdtjd}|S)NrrG)rrrJr r')rLs rget_secrets_auth_sectionrONs8B=1.3.2, e.g. via `pip install Authlib`.NalgHS256r;)minutes)rrzlatin-1) authlib.joserQrAr rnowrutcrencoderMdecode)rrQheaderpayloadprovider_tokens rencode_provider_tokenr^Ws$ W F||HLL)Ia,@@G JJvw8J8LMN   ++  u  s A++Bc ddlm}m}m}ddiddid} |j |t|}|jtd |S#t$r t ddwxYw#|$r}t d |dd}~wwxYw) z-Decode the JWT token and validate the claims.r) JoseError JWTClaimsrQrRN essentialT)rr)claims_optionszError decoding provider token: r) rVr`rarQrAr rZrMvalidater )r]r`rarQ claim_optionsr\es rdecode_provider_tokenrgjs::)$/k4=PQMR ZZ .0(   & 00!  u   R #B1#!FGTQRs" A,A'A$'B,A;;Bc vi}|jdr|jd|d<|jdr|jd|d<|jdr|jd|d<|jdr6td|jdtij|d<|S)zKGenerate a default provider section for the 'auth' section of secrets.toml. client_id client_secretserver_metadata_url client_kwargsr)r'r rto_dict)rLdefault_provider_sections r!generate_default_provider_sectionros! $0<0@0@0M -(4@4D4D_4U 1-.:F:J:J !;  !67(48  (((2,G5 ') !1 $#rc8tjs tdtjd}| tdd|vr tdd|vr td|j|}d|vrtd |d ||d k(r t |}||d k(r td td |dt |t std|dgd}|Dcgc] }||vs| }}|r&|d k(rtd|dtd|d|dycc}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`.rGN redirect_urizAuthentication credentials in `.streamlit/secrets.toml` are missing the "redirect_uri" key. Please check your configuration.rHzAuthentication credentials in `.streamlit/secrets.toml` are missing the "cookie_secret" key. Please check your configuration._zAuth 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.)rirjrkzAuthentication 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: )rrJr r'ro isinstancer)rrLprovider_section required_keysr) missing_keyss rvalidate_auth_credentialsrxs  0 0 2  O  %((0L  O  \)  D  l*  E  $''1 h "8*-> ?  H $9<\J y $Y !,,4:6   & 0 ((0z2" #  JM#0PCC?O4OCPLP y $S. BD  ! ((0z1Sn> @  Qs  D(DN)r3bool)r3r)r3r)rrr3r)r]rr3r)rLrr3r5)rrr3r4) __future__rcollections.abcrrrrtypingrr r r streamlitr streamlit.errorsr streamlit.runtime.secretsrrrrrErMrOr^rgrorxrrrrs_##2266/Ay ""* ,&1.$$H r