
    #	h2,                         S SK r  S SKJr  S SKr\R
                  " \5      rSrSr	Sr
Sr\" \\	S\/5      r/ SQrSr " S	 S
\5      r " S S\5      rS rS rS rg! \ a	    S SKJr   N^f = f)    N)urlparsezlogin.microsoftonline.uszlogin.chinacloudapi.cnzlogin.microsoftonline.comzlogin-us.microsoftonline.com)zb2clogin.comzb2clogin.cnzb2clogin.uszb2clogin.dezciamlogin.comz.ciamlogin.comc                        \ rS rSrS rS rSrg)AuthorityBuilder"   c                 \    UR                  S5      U l        UR                  S5      U l        g)zA helper to save caller from doing string concatenation.

Usage is documented in :func:`application.ClientApplication.__init__`.
/N)rstrip	_instancestrip_tenant)selfinstancetenants      @/var/www/html/env/lib/python3.13/site-packages/msal/authority.py__init__AuthorityBuilder.__init__#   s$    
 "-||C(    c                 N    SR                  U R                  U R                  5      $ )Nzhttps://{}/{})formatr
   r   )r   s    r   __str__AuthorityBuilder.__str__+   s    %%dnndllCCr   )r
   r   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__ r   r   r   r   "   s    )Dr   r   c                   N    \ rS rSrSr\" / 5      r   S	S jrS rS r	S
S jr
Srg)	Authority/   zThis class represents an (already-validated) authority.

Once constructed, it contains members named "*_endpoint" for this instance.
TODO: It will also cache the previously-validated authority instances.
Nc                 ,   X l         U(       a(  [        R                  SU5        U R                  U5      nO([        R                  SU5        U R	                  XU5      n [        UU R                   5      n[        R                  SXg5        US   U l        US	   U l	        UR                  S
5      U l        [        U R                  5      u    ol        g! [         a6    U(       a  SR                  US9OSR                  U5      S-   n[        U5      ef = f)a0  Creates an authority instance, and also validates it.

:param validate_authority:
    The Authority validation process actually checks two parts:
    instance (a.k.a. host) and tenant. We always do a tenant discovery.
    This parameter only controls whether an instance discovery will be
    performed.
z$Initializing with OIDC authority: %sz%Initializing with Entra authority: %szUnable to get OIDC authority configuration for {url} because its OIDC Discovery endpoint is unavailable at {url}/.well-known/openid-configuration )urlzUnable to get authority configuration for {}. Authority would typically be in a format of https://login.microsoftonline.com/your_tenant or https://tenant_name.ciamlogin.com or https://tenant_name.b2clogin.com/tenant.onmicrosoft.com/policy. z> Also please double check your tenant name or GUID is correct.zopenid_config("%s") = %sauthorization_endpointtoken_endpointdevice_authorization_endpointN)_http_clientloggerdebug_initialize_oidc_authority_initialize_entra_authoritytenant_discovery
ValueErrorr   r#   r$   getr%   canonicalizer   )
r   authority_urlhttp_clientvalidate_authorityinstance_discoveryoidc_authority_urltenant_discovery_endpointopenid_configerror_message_s
             r   r   Authority.__init__7   s#    (LL?AST(,(G(G")$% LL@-P(,(H(H3E)G%	,,)!!#M" 	&(A	R&34L&M#+,<=-:->->?^-_*()<)<=1k'  	,
 &::@&EW&:XV
 &TUM ]++	,s   C A Dc                 ~    [        U5      u  o l        nUR                  5       S:H  U l        SU l        SU l        US-   $ )NadfsTz!/.well-known/openid-configuration)r.   r   loweris_adfs_is_b2c_is_known_to_developer)r   r3   	authorityr   s       r   r)   $Authority._initialize_oidc_authorityg   sC    +78J+K(	=&||~/ '+#!$GGGr   c                   ^  [        U[        5      (       a  [        U5      n[        U5      u  nT l        nT R                  R                  [        5      nUR                  5       S:H  =(       a    U(       + T l        UR                  R                  S5      n[        U 4S j[         5       5      =(       d7    [        U5      S:H  =(       a"    US   R                  5       R                  S5      T l        T R                  =(       d    T R                  =(       d    U(       + T l        T R                  ["        ;   nUS;   a  SR%                  [&        5      OUn	U	(       a}  U(       dv  T R                   (       de  [)        S	R%                  T R                  UR                  5      T R*                  U	5      n
U
R-                  S
5      S:X  a  [/        SU-  5      eU
S   nU$ UR1                  SR%                  U(       a  [        UR                  5      S::  a  UOUR                  T R                  (       a  SOSS9S9R3                  5       nU$ )Nr:   r   c              3   `   >#    U  H#  nTR                   R                  S U-   5      v   M%     g7f).N)r   endswith).0dr   s     r   	<genexpr>8Authority._initialize_entra_authority.<locals>.<genexpr>}   s+      5IDMM""37++5Is   +.      b2c_)NTz$https://{}/common/discovery/instancez"https://{}{}/oauth2/v2.0/authorizeerrorinvalid_instancezinvalid_instance: The authority you provided, %s, is not whitelisted. If it is indeed your legit customized domain name, you can turn off this check by passing in instance_discovery=Falser4   z2{prefix}{version}/.well-known/openid-configuration    z/v2.0)prefixversion)path)
isinstancer   strr.   r   rD   _CIAM_DOMAIN_SUFFIXr;   r<   rR   splitanyWELL_KNOWN_B2C_HOSTSlen
startswithr=   r>   WELL_KNOWN_AUTHORITY_HOSTSr   
WORLD_WIDE_instance_discoveryr&   r-   r,   _replacegeturl)r   r/   r1   r2   r?   r   is_ciampartsis_known_to_microsoftinstance_discovery_endpointpayloadr4   s   `           r   r*   %Authority._initialize_entra_authorityp   s     m%566.M+7+F(	4=&--(()<=||~/?K$$S) 5I  Ke*/IeAhnn&6&A&A&&I 	 '+ll&\dll&\J\F\# $1K K
 $|3	 'M&S&S' :L	 	$
 '%)D)D)4;;MM9>>3!!+	-G
 {{7#'99 /
 $$% % )00K(L% )( )2(:(:IPP%,Y^^1D1I6&^^"&,,BG Q  ); ) &( & )(r   c                    U R                   U R                  R                  ;  a  U=(       d5    U R                  R	                  SR                  U R                   US9SUS.S9nUR                  S:w  a0  UR                  5         [        R                  " UR                  5      $ U R                  R                  R                  U R                   5        0 $ )Nz<https://{netloc}/common/userrealm/{username}?api-version=1.0)netlocusernamezapplication/json)Acceptzclient-request-id)headersi  )r   	__class__%_domains_without_user_realm_discoveryr&   r-   r   status_coderaise_for_statusjsonloadstextadd)r   rh   correlation_idresponseresps        r   user_realm_discoveryAuthority.user_realm_discovery   s     == T TT @t0044NUU==8 V =#5.<>  5  @D
 3&%%'zz$)),,NN@@DDT]]S	r   )	r&   r=   r>   r#   r%   r   r<   r   r$   )TNN)NN)r   r   r   r   __doc__setrl   r   r)   r*   rv   r   r   r   r   r   r   /   s5    
 -0G)  $##	.>`H/)br   r   c                    [        U 5      nUR                  S:X  a  UR                  R                  S5      n[	        U5      S:  a  US   (       a  US   OS nUR
                  R                  [        5      (       aI  U(       a  UO1SR                  UR
                  R                  [        S5      S   5      nXR
                  U4$ [	        U5      S:  a  US   (       a  XR
                  US   4$ [        SU -  5      e)Nhttpsr   rJ   rN   z{}.onmicrosoft.comr   a
  Your given address (%s) should consist of an https url with a minimum of one segment in a path: e.g. https://login.microsoftonline.com/{tenant} or https://{tenant_name}.ciamlogin.com/{tenant} or https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/policy)r   schemerR   rV   rY   hostnamerD   rU   r   rsplitr,   )authority_or_auth_endpointr?   ra   
first_partr   s        r   r.   r.      s    34I7"$$S)!$UqU1XU1X4
&&':;;#-Z3G3N3N""))*=qA!D4FF 00&88u:?uQx00%(::
	U
 %	%& &r   c                 r    UR                   " U4SU SS.0UD6n[        R                  " UR                  5      $ )Nparamsz1.0)r#   zapi-version)r-   ro   rp   rq   )r"   r0   rc   kwargsru   s        r   r]   r]      s?    ??#*-eD D ::dii  r   c                    UR                   " U 40 UD6nUR                  S:X  a   [        R                  " UR                  5      $ SUR                  s=::  a  S:  a3  O  O0[        SR                  U UR                  UR                  5      5      eUR                  5         [        SUR                  UR                  4-  5      e)N   i  i  z7OIDC Discovery failed on {}. HTTP status: {}, Error: {}z)Unable to complete OIDC Discovery: %d, %s)	r-   rm   ro   rp   rq   r,   r   rn   RuntimeError)r4   r0   r   ru   s       r   r+   r+      s    ??4??D3zz$))$$
d$$ RYY%II  	 	
3t7G7G6SSU Ur   )ro   urllib.parser   ImportErrorlogging	getLoggerr   r'   AZURE_US_GOVERNMENTAZURE_CHINAAZURE_PUBLICr\   ry   r[   rX   rU   objectr   r   r.   r]   r+   r   r   r   <module>r      s    "%  
		8	$ 1 &*(
 "	"    ' 
Dv 
D@ @F&.!UY  "!"s   A A+*A+