
    #	hM2                        S r SSKrSSKrSSKrSSKrSSKrSSKJrJr  \R                  " \
5      r SSKr\R                  " S 5         " S S\5      r " S S\5      rSrS rS rSS jrS rS rS r   SS jr      SS jr  SS jrSS jr S r!g! \\4 a:    SSS.R!                  \R"                  5      r\(       a  \" S	\ S
35      e\" S5      ef = f) zThis module is an adaptor to the underlying broker.
It relies on PyMsalRuntime which is the package providing broker's functionality.
    N   )__version__SKUc                 >   [         R                  R                  [        R                  [         R                  R
                  [        R                  [         R                  R                  [        R                  0R                  U[        R                  5      " U 5      $ N)	pymsalruntimeLogLevelTRACEloggerdebugDEBUGFATALcriticalget)messagelevels     =/var/www/html/env/lib/python3.13/site-packages/msal/broker.py<lambda>r      sl    $$fll$$fll
 	$$fooD
 #eV\\
"D# $+D,    z1.20z1.31)win32darwinz;You must install dependency by: pip install "msal[broker]>=z,<2"z8Dependency pymsalruntime unavailable on current platformc                       \ rS rSrSrg)RedirectUriError'    N__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r   '       r   r   c                       \ rS rSrSrg)TokenTypeError+   r   Nr   r   r   r   r$   r$   +   r"   r   r$   z$msauth.com.msauth.unsignedapp://authc                 T   U R                  5       nSU;   d  SU;   a  [        SR                  U[        5      5      eSSR                  UU R	                  5       U R                  5       U R                  5       5      U R	                  5       U R                  5       U R                  5       S.$ )NAADSTS50011AADSTS7000218zwMsalRuntime needs the current app to register these redirect_uri (1) ms-appx-web://Microsoft.AAD.BrokerPlugin/{} (2) {}broker_errorz'{}. Status: {}, Error code: {}, Tag: {})errorerror_description_broker_status_broker_error_code_broker_tag)get_contextr   format_redirect_uri_on_mac
get_statusget_error_codeget_tag)r*   	client_idcontexts      r   _convert_errorr7   7   s    !GW$')EEKV+F-. 	.   GMM 4 4 6I  **,#224}}

 

r   c                 d   [         R                  " 5       n[         R                  " U UU4S j5        UR                  R	                  5         UR
                  R                  5       nU(       a!  [        R                  S[        US5      5        gUR
                  R                  5       nU(       a  U$ g)zEReturn an instance of MSALRuntimeError or MSALRuntimeAccount, or Nonec                 $    UR                  U 5      $ r   completeresultcallback_datas     r   r   %_read_account_by_id.<locals>.<lambda>V       M4J4J64Rr   zread_account_by_id() error: %sN)r   CallbackDataread_account_by_idsignalwaitr=   	get_errorr   r   r7   get_account)
account_idcorrelation_idr>   r*   accounts        r   _read_account_by_idrJ   P   s    !..0M$$%2R

   **,E5~eT7RS""..0Gr   c                 D   U R                  5       nUR                  SS 5        U R                  5       nU(       a  [        [	        XA5      US9$ U R                  5       (       a$  [        R                  " U R                  5       5      O0 nU R                  5       nU(       d   S5       eU R                  5       (       a!  U R                  5       R                  5       S   OU R                  5       U R                  5       [        [        R                  " 5       5      -
  U R!                  5       UUR#                  5       UR%                  5       U R                  5       (       a  SO
U=(       d    SS.R'                  5        VVs0 s H  u  pxU(       d  M  Xx_M     n	nnU	S   R)                  S	5      n
U	S
   R+                  5       S:X  a'  U
(       d   [-        SR/                  U	S   S S 5      5      eU R1                  5       nU(       a  SR3                  U5      U	S'   [        XS9$ s  snnf )Nwam_telemetry)_msalruntime_telemetryz*Account is expected to be always availabler   popbearer)access_token
expires_inid_tokenid_token_claimsclient_info_account_id
token_typerP   AAAArV   zssh-certz'Broker could not get an SSH Cert: {}...    scope)get_telemetry_datarN   rE   dictr7   get_id_tokenjsonloadsrF   is_pop_authorizationget_authorization_headersplitget_access_tokenget_access_token_expiry_timeinttimeget_raw_id_tokenget_client_infoget_account_iditems
startswithlowerr$   r0   get_granted_scopesjoin)r=   r5   expected_token_type	telemetryr*   rS   rI   kvreturn_valuelikely_a_certgranted_scopess               r   _convert_resultrv   c   s   ))+IMM/4(EN54YWW;A;N;N;P;Pdjj!4!4!67VXO  "G@@@7 **,, ++-282I2I2K99;c$))+>NN++-*..0--/4466+8&
 %'&  &TQ  AD &L  !0;;FCML!'')Z7FMM(!,. / 	/..0N # 8W??)s   <HHc                  >    [        [        R                  " 5       5      $ r   )struuiduuid4r   r   r   _get_new_correlation_idr{      s    tzz|r   c                 (    U R                  SS5        g )Nmsal_request_typeconsumer_passthrough)set_additional_parameter)paramss    r   _enable_msa_ptr      s    
##$79OPr   c                     [         R                  " X5      nUR                  S[        5        UR                  S[        5        U$ )Nmsal_client_skumsal_client_ver)r   MSALRuntimeAuthParametersr   r   r   )r5   	authorityr   s      r   _build_msal_runtime_auth_paramsr      s9    44YJF
##$5s;
##$5{CMr   c                    [        X5      nUR                  U5        U(       a  UR                  U5        U(       aP  UR                  UR                  UR
                  R                  UR
                  R                  UR                  5        [        R                  " 5       n	UR                  5        H%  u  pUc  M
  UR                  U
[        U5      5        M'     U(       a  [        U5        [        R                  " UU=(       d
    [!        5       U	4S j5        U	R"                  R%                  5         ['        U	R(                  XR+                  S5      S9$ )Nc                 $    UR                  U 5      $ r   r:   r<   s     r   r   "_signin_silently.<locals>.<lambda>   r@   r   rV   ro   )r   set_requested_scopesset_decoded_claimsset_pop_params_http_method_urlnetlocpath_noncer   rA   rj   r   rx   r   signin_silentlyr{   rC   rD   rv   r=   r   )r   r5   scopesrH   claimsenable_msa_ptauth_schemekwargsr   r>   rq   rr   s               r   _signin_silentlyr      s   
 -YBF
'!!&)$$k&6&6&=&={?O?O?T?T	  "..0M=++As1v6  v!!313%2RT iZZ=UW Wr   c
                 "   [        X5      nUR                  U5        UR                  [        R                  S:X  a  [
        OS5        U(       a;  US:X  a  U(       a  S n[        R                  S5        O[        R                  SU5        Uc  UR                  SS5        U(       a  [        U5        U	(       aP  UR                  U	R                  U	R                  R                  U	R                  R                  U	R                  5        U
R!                  5        H%  u  pUc  M
  UR                  U[#        U5      5        M'     U(       a  UR%                  U5        [&        R(                  " SS	9n[&        R*                  " U=(       d1    [&        R,                  " 5       =(       d    [&        R.                  " 5       UU=(       d
    [1        5       UU4S
 j5        UR2                  R5                  5         [7        UR8                  XR;                  S5      S9$ )Nr   z<https://login.microsoftonline.com/common/oauth2/nativeclientselect_accountzKUsing both select_account and login_hint is ambiguous. Ignoring login_hint.z)prompt=%s is not supported by this modulemsal_gui_threadtrueT)is_interactivec                 $    UR                  U 5      $ r   r:   r<   s     r   r   '_signin_interactively.<locals>.<lambda>   r@   r   rV   r   )r   r   set_redirect_urisysplatformr1   r   warningr   r   r   r   r   r   r   r   rj   rx   r   r   rA   signin_interactivelyget_console_windowget_desktop_windowr{   rC   rD   rv   r=   r   )r   r5   r   parent_window_handleprompt
login_hintr   rH   r   r   r   r   rq   rr   r>   s                  r   _signin_interactivelyr      s    -YBF
'
 # 8F %% "
lmNNFO#''(96Bv$$k&6&6&=&={?O?O?T?T	  =++As1v6  !!&)!..dCM&&h @ @ BhmFfFfFh313%2RT iZZ=UW Wr   c                    U=(       d
    [        5       n[        X%5      nUc  g [        X5      n	U	R                  U5        U(       a  U	R	                  U5        U(       aP  U	R                  UR                  UR                  R                  UR                  R                  UR                  5        UR                  5        H%  u  pUc  M
  U	R                  U
[        U5      5        M'     [        R                  " 5       n[        R                   " U	UUU4S j5        UR"                  R%                  5         ['        UR(                  XR+                  S5      S9$ )Nc                 $    UR                  U 5      $ r   r:   r<   s     r   r   )_acquire_token_silently.<locals>.<lambda>   r@   r   rV   r   )r{   rJ   r   r   r   r   r   r   r   r   r   rj   r   rx   r   rA   acquire_token_silentlyrC   rD   rv   r=   r   )r   r5   rG   r   r   rH   r   r   rI   r   rq   rr   r>   s                r   _acquire_token_silentlyr      s    $@'>'@N!*=G,YBF
'!!&)$$k&6&6&=&={?O?O?T?T	  =++As1v6  "..0M((%2R	T
 iZZ=UW Wr   c                 8   U=(       d
    [        5       n[        X5      nUc  g [        R                  " 5       n[        R                  " U UUU4S j5        UR
                  R                  5         UR                  R                  5       nU(       a  [        XP5      $ g )Nc                 $    UR                  U 5      $ r   r:   r<   s     r   r   #_signout_silently.<locals>.<lambda>  r@   r   )
r{   rJ   r   rA   signout_silentlyrC   rD   r=   rE   r7   )r5   rG   rH   rI   r>   r*   s         r   _signout_silentlyr     s    #@'>'@N!*=G!..0M""%2R	T
   **,Ee// r   c                  0    [         R                  " S5        g )Nr   )r   set_is_pii_enabledr   r   r   _enable_pii_logr     s    $$Q'r   r   )NNFN)NNNNFN)NNN)"__doc__r^   loggingr   rf   ry   skur   r   	getLoggerr   r   r   register_logging_callbackImportErrorAttributeErrorr   r   min_ver
ValueErrorr   r$   r1   r7   rJ   rv   r{   r   r   r   r   r   r   r   r   r   r   <module>r      s>     
   !			8	$V++ -, -0	z 		Z 	 > 
2&@BQ CGW> 5Wr OSW@0 ({ 	^$ V  
c#,,  I'RVWY 	Y TUUVs   B AC