Ë
    £…j@>  ã                   óx  — d Z ddlZddlZddlZddlZddlZddlZddlZddlZdZ	 ej                  «       Z ej                  d„ «       dZdZ ej                  ej                  j                   dd¬	«      Zd
„ Zd„ Zd*d„Zddedfd„Z ed«      Z ej0                  erej2                  nej4                  ¬«       	 ddlmZ  e«         ej:                  d«       d„ Z d„ Z!d„ Z"d+d„Z#d„ Z$d„ Z%dZ&dde&dœZ'd gZ(d!„ Z)d"„ Z*d#„ Z+d$„ Z,d%„ Z-d&„ Z.d'„ Z/d(„ Z0e1d)k(  r e0«        yy# e$ r  ej>                  d«       Y Œ]w xY w),a  MSAL Python Tester

Usage 1: Run it on the fly.
    python -m msal
    Note: We choose to not define a console script to avoid name conflict.

Usage 2: Build an all-in-one executable file for bug bash.
    shiv -e msal.__main__._main -o msaltest-on-os-name.pyz .
é    Nzmsal_cache.binc                  óˆ   — t         j                  r1t        t        d«      j	                  t         j                  «       «      S d S )NÚw)Úglobal_cacheÚhas_state_changedÚopenÚ_token_cache_filenameÚwriteÚ	serialize© ó    úN/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/msal/__main__.pyú<lambda>r      s=   € ô ×%Ò%ô 	Ô	 Ó$×*Ñ*¬<×+AÑ+AÓ+CÓDð ð ,0ð r   z$04b07795-8ddb-461a-bbee-02f9e1bf7b46z$04f0c124-f2bc-4f59-8241-bf6df9866bbdzhttps://example.com/endpointÚplaceholder)Úhttp_methodÚurlÚnoncec                 óF   — t        t        j                  | dd¬«      «       y )Né   T)ÚindentÚ	sort_keys)ÚprintÚjsonÚdumps)Úblobs    r   Ú
print_jsonr      s   € Ü	Œ$�*‰*�T !¨tÔ
4Õ5r   c                 ó:   — t        dj                  | «      «      dvS )Nz9{} (N/n/F/f or empty means False, otherwise it is True): )ÚNÚnÚFÚfÚ )ÚinputÚformat)Úmessages    r   Ú_input_booleanr%   "   s%   € ÜØC×JÑJÈ7ÓSó
à)ð*ð *r   c                 ó\   — t        | j                  |¬«      «      j                  «       xs |S )N)Údefault)r"   r#   Ústrip)r$   r'   s     r   Ú_inputr)   '   s&   € Ü�—‘¨�Ó0Ó1×7Ñ7Ó9ÒD¸WÐDr   zYour options:z    Your choice? Fc           	      óR  — | sJ d«       ‚|rt        |«       t        | d¬«      D ]&  \  }}t        dj                  | ||«      «      «       Œ( |rt        d«       	 t        |«      }	 t	        |«      }d|cxk  rt        | «      k  rn n| |dz
     S Œ7# t        $ r |r|r|cY S Y Œw xY w)Nzoptions must not be emptyé   )Ústartz
    {}: {}z'    Or you can just type in your input.)r   Ú	enumerater#   r"   ÚintÚlenÚ
ValueError)	ÚoptionsÚheaderÚfooterÚoption_rendererÚaccept_nonempty_stringÚiÚoÚraw_dataÚchoices	            r   Ú_select_optionsr:   *   s¸   € ñ Ð/Ð/Ó/ˆ7ÙÜˆfŒÜ˜'¨Ô+ò :‰ˆˆ1Üˆl×!Ñ! !¡_°QÓ%7Ó8Õ9ð:áÜÐ7Ô8Ø
Ü˜“=ˆð	 Ü˜“]ˆFØ�FÔ*œc '›lÕ*Ø˜v¨™zÑ*Ð*ð øô ò 	 ÙÑ2Ø’ùð	 ús   Á')B ÂB&Â%B&zEnable MSAL Python's DEBUG log?)Úlevel)Úload_dotenvz+Loaded environment variables from .env filezSpython-dotenv is not installed. You may need to set environment variables manually.c                  ó`   — t        g d¢dd¬«      j                  «       } d| v rt        d«      ‚| S )N)z$https://graph.microsoft.com/.defaultz%https://management.azure.com/.defaultz	User.ReadzUser.ReadBasic.Allz_Select a scope (multiple scopes can only be input by manually typing them, delimited by space):T©r2   r5   ú4https://pas.windows.net/CheckMyAccess/Linux/.defaultz9SSH Cert scope shall be tested by its dedicated functions)r:   Úsplitr0   ©Úscopess    r   Ú_input_scopesrC   J   sA   € Üò 
ð qØ#ô
÷ ‰%‹'ð ð >ÀÑGÜÐTÓUÐUØ€Mr   c                 ó\   — | j                  «       }|rt        |d„ d¬«      S t        d«       y )Nc                 ó2   — dj                  | d   | d   «      S )Nz{}, came from {}ÚusernameÚaccount_source)r#   ©Úas    r   r   z!_select_account.<locals>.<lambda>]   s   € Ð&8×&?Ñ&?ÀÀ*ÁÈqÐQaÑObÓ&c€ r   z0Account(s) already signed in inside MSAL Python:©r4   r2   zRNo account available inside MSAL Python. Use other methods to acquire token first.)Úget_accountsr:   r   )ÚappÚaccountss     r   Ú_select_accountrN   X   s4   € Ø×ÑÓ!€HÙÜØÙcØEôð 	ô 	ÐbÕcr   c           
      óÀ   — t        | «      }|rQt        | j                  t        «       |t	        d«      | j                  «       rt	        d«      rt        nd¬«      «       yy)zIacquire_token_silent() - with an account already signed into MSAL Python.ú!Bypass MSAL Python's token cache?úAcquire AT POP via Broker?N)ÚaccountÚforce_refreshÚauth_scheme)rN   r   Úacquire_token_silent_with_errorrC   r%   Úis_pop_supportedÚplaceholder_auth_scheme©rL   rR   s     r   Ú_acquire_token_silentrY   c   s[   € ä˜cÓ"€GÙÜ�3×6Ñ6Ü‹OØÜ(Ð)LÓMà×'Ñ'Ô)¬nÐ=YÔ.Zõ 0àð 7ó õ 	ð r   c                 ó–  — t        | t        j                  «      sJ ‚|xs
 t        «       }t	        dddœdddœdddœgd„ d	¬
«      d   }|dk(  rd}nHt	        dg| j                  «       D �cg c]  }|d   ‘Œ	 c}z   dd¬«      }t        |t        «      r|d   n|}| j                  || j                  | j                  t        t        fv d|||xs i | j                  «       rt        d«      rt        nd¬«      }|r@d|v r<|j                  di «      j                  d«      }||k7  rt!        j"                  d|«       t%        |«       |S c c}w )zUacquire_token_interactive() - User will be prompted if app opts to do select_account.NzRUnspecified. Proceed silently with a default account (if any), fallback to prompt.)ÚvalueÚdescriptionÚnonezEnone. Proceed silently with a default account (if any), or error out.Úselect_accountz.select_account. Prompt with an account picker.c                 ó   — | d   S )Nr\   r   ©r7   s    r   r   z,_acquire_token_interactive.<locals>.<lambda>y   s   €  ! MÑ"2€ r   zPrompt behavior?rJ   r[   rF   zŸlogin_hint? (If you have multiple signed-in sessions in browser/broker, and you specify a login_hint to match one of them, you will bypass the account picker.)Tr>   iÒ  rQ   )Úparent_window_handleÚenable_msa_passthroughÚportÚpromptÚ
login_hintÚdatarT   Úid_token_claimsÚpreferred_usernamez-Signed-in user "%s" does not match login_hint)Ú
isinstanceÚmsalÚPublicClientApplicationrC   r:   rK   ÚdictÚacquire_token_interactiveÚCONSOLE_WINDOW_HANDLEÚ	client_idÚ
_AZURE_CLIÚ_VISUAL_STUDIOrV   r%   rW   ÚgetÚloggingÚwarningr   )	rL   rB   rf   rd   re   rI   Úraw_login_hintÚresultÚsigned_in_users	            r   Ú_acquire_token_interactiverx   p   st  € ä�cœ4×7Ñ7Ô8Ð8Ð8ØÒ&”}“€FÜØÐ'{Ñ|ØÐ)pÑqØ"Ð3cÑdð
ñ
 3Ø!ô#ð $+ñ,€Fð Ð!Ò!Ø‰
ä(ØˆF¨S×-=Ñ-=Ó-?Ö@¨�a˜
“mÒ@Ñ@ð uØ#'ôˆô
 4>¸nÌdÔ3S�^ JÒ/ÐYgˆ
Ø×*Ñ*ØØ ×6Ñ6Ø"Ÿ}™}Üœð1ð  ð Ø *°4²:¸2à×#Ñ#Ô%¬.Ð9UÔ*Võ ,àð +ó 
€Fñ Ð'¨6Ñ1ØŸ™Ð$5°rÓ:×>Ñ>Ð?SÓTˆØ˜ZÒ'Ü�O‰OÐKÈ^Ô\ÜˆvÔØ€Mùò- As   Á*E
c                 ó†   — t        | j                  t        d«      t        j                  d«      t	        «       ¬«      «       y)z«acquire_token_by_username_password() - See constraints here: https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#constraints-for-ropcz
username: z
password: rA   N)r   Ú"acquire_token_by_username_passwordr)   ÚgetpassrC   ©rL   s    r   Ú#_acquire_token_by_username_passwordr}   —   s5   € äˆs×5Ñ5Üˆ|ÓœgŸo™o¨lÓ;ÄMÃOð 6ó Uõ Vr   c                 ó  — t        | t        j                  «      sJ ‚| j                  t	        «       ¬«      }t        |d   «       t        j                  j                  «        t        d«       | j                  |«      }t        |«       y)zNacquire_token_by_device_flow() - Note that this one does not go through brokerrA   r$   zNAfter you completed the step above, press ENTER in this console to continue...N)ri   rj   rk   Úinitiate_device_flowrC   r   ÚsysÚstdoutÚflushr"   Úacquire_token_by_device_flowr   )rL   Úflowrv   s      r   Ú_acquire_token_by_device_flowr…   œ   sj   € ä�cœ4×7Ñ7Ô8Ð8Ð8Ø×#Ñ#¬=«?Ð#Ó;€DÜ	ˆ$ˆy‰/ÔÜ‡J�J×ÑÔÜ	Ð
ZÔ[Ø×-Ñ-¨dÓ3€FÜˆvÕr   aw  {"kty":"RSA", "n":"2tNr73xwcj6lH7bqRZrFzgSLj7OeLfbn8216uOMDHuaZ6TEUBDN8Uz0ve8jAlKsP9CQFCSVoSNovdE-fs7c15MxEGHjDcNKLWonznximj8pDGZQjVdfK-7mG6P6z-lgVcLuYu5JcWU_PeEqIKg5llOaz-qeQ4LEDS4T1D2qWRGpAra4rJX1-kmrWmX_XIamq30C9EIO0gGuT4rc2hJBWQ-4-FnE1NXmy125wfT3NdotAJGq5lMIfhjfglDbJCwhc8Oe17ORjO3FsB5CLuBRpYmP7Nzn66lRY3Fe11Xz8AEBl3anKFSJcTvlMnFtu3EpD-eiaHfTgRBU7CztGQqVbiQ", "e":"AQAB"}ússh-certÚkey1)Ú
token_typeÚkey_idÚreq_cnfr?   c                 ó  — t        | t        j                  «      sJ ‚t        | «      }|r_| j	                  t
        |t        t        d«      ¬«      }t        |«       |r+|j                  d«      dk7  rt        j                  d«       yyyy)zFAcquire an SSH Cert silently- This typically only works with Azure CLIrP   )rf   rS   rˆ   r†   zUnable to acquire an ssh-cert.N)ri   rj   rk   rN   Úacquire_token_silentÚ_SSH_CERT_SCOPEÚ_SSH_CERT_DATAr%   r   rr   rs   Úerror)rL   rR   rv   s      r   Ú_acquire_ssh_cert_silentlyr�   ª   s‚   € ä�cœ4×7Ñ7Ô8Ð8Ð8Ü˜cÓ"€GÙØ×)Ñ)ÜØÜÜ(Ð)LÓMð	 *ó ˆô 	�6ÔÙ�f—j‘j Ó.°*Ò<Ü�M‰MÐ:Õ;ð =ˆ6ð r   c                 ó¼   — t        | t        j                  «      sJ ‚t        | t        t
        ¬«      }|j                  d«      dk7  rt        j                  d«       yy)zLAcquire an SSH Cert interactively - This typically only works with Azure CLI)rB   rf   rˆ   r†   zUnable to acquire an ssh-certN)	ri   rj   rk   rx   r�   rŽ   rr   rs   r�   )rL   rv   s     r   Ú_acquire_ssh_cert_interactiver’   ¹   sI   € ä�cœ4×7Ñ7Ô8Ð8Ð8Ü'¨´OÌ.ÔY€FØ‡z�z�,Ó :Ò-Ü�‰Ð5Õ6ð .r   c                 ó°   — t        | t        j                  «      sJ ‚dg}t        | |¬«      }|j	                  d«      dk7  rt        j                  d«       yy)zLAcquire a POP token interactively - This typically only works with Azure CLIz-6256c85f-0aad-4d50-b960-e6e9b21efe35/.defaultrA   rˆ   ÚpopzUnable to acquire a pop tokenN)ri   rj   rk   rx   rr   rs   r�   )rL   Ú	POP_SCOPErv   s      r   Ú_acquire_pop_token_interactiver–   À   sO   € ä�cœ4×7Ñ7Ô8Ð8Ð8Ø@ÐA€IÜ'¨°IÔ>€FØ‡z�z�,Ó 5Ò(Ü�‰Ð5Õ6ð )r   c                 ó|   — t        | «      }|r/| j                  |«       t        dj                  |d   «      «       yy)zoremove_account() - Invalidate account and/or token(s) from cache, so that acquire_token_silent() would be resetz@Account "{}" and/or its token(s) are signed out from MSAL PythonrF   N)rN   Úremove_accountr   r#   rX   s     r   Ú_remove_accountr™   È   s=   € ä˜cÓ"€GÙØ×Ñ˜7Ô#ÜÐP×WÑWÐX_Ð`jÑXkÓlÕmð r   c                 ó‚   — t        | t        j                  «      sJ ‚t        | j	                  t        «       ¬«      «       y)zKCCA.acquire_token_for_client() - Rerun this will get same token from cache.rA   N)ri   rj   ÚConfidentialClientApplicationr   Úacquire_token_for_clientrC   r|   s    r   Ú_acquire_token_for_clientr�   Ï   s0   € ä�cœ4×=Ñ=Ô>Ð>Ð>Üˆs×+Ñ+´=³?Ð+ÓCÕDr   c                 ó\   — t        | t        j                  «      sJ ‚| j                  «        y)zECCA.remove_tokens_for_client() - Run this to evict tokens from cache.N)ri   rj   r›   Úremove_tokens_for_clientr|   s    r   Ú_remove_tokens_for_clientr    Ô   s$   € ä�cœ4×=Ñ=Ô>Ð>Ð>Ø× Ñ Õ"r   c                 ó€   — | j                   rdnd}t        dj                  |«      «       t        j                  «        y)ÚExitzjhttps://identitydivision.visualstudio.com/Engineering/_queries/query/79b3a352-a775-406f-87cd-a487c382a8ed/zXhttps://github.com/AzureAD/microsoft-authentication-library-for-python/issues/new/choosez2Bye. If you found a bug, please report it here: {}N)Ú_enable_brokerr   r#   r€   Úexit)rL   Úbug_links     r   Ú_exitr¦   Ù   s:   € ð ×Òñ 	uàbð ô
 
Ð
>×
EÑ
EÀhÓ
OÔPÜ‡H�H…Jr   c                  óÞ  — t        dj                  t        j                  «      «       t	        dddœddj                  t
        «      dœgd„ dd	¬
«      } | d   dk(  rUt        j                  j                  t
        «      r2	 t        j                  t        t
        d«      j                  «       «       t	        t        ddœt        ddœdddœt        j                   d«      t        j                   d«      ddœgd„ dd¬
«      }t#        |t$        «      xr d|v }|r|d   r|d   st'        d«      ‚| xr t)        d«      }|rt*        rt)        d«      nd	}t	        g d¢dd¬ «      }|r|j-                  d!«      st)        d"«      nd }|s7t        j.                  t#        |t$        «      r|d   n||||||||t        ¬#«	      n$t        j0                  |d   |d   |||t        ¬$«      }t2        gt#        |t        j.                  «      rt4        t6        t8        t:        t<        gng z   t>        t@        gz   t#        |t        j0                  «      rtB        tD        gng z   }	 t	        |tF        gz   d%„ d&¬'«      }		  |	|«       Œ!# t        $ r Y �ŒÒw xY w# t&        $ r }
tI        jJ                  d(|
«       Y d }
~
Œ5d }
~
wtL        $ r t        d)«       Y ŒNtN        $ r }
tI        jJ                  d*|
«       Y d }
~
Œqd }
~
ww xY w)+Nz4Welcome to the Msal Python {} Tester (Experimental)
Úemptyz<Start with an empty token cache. Suitable for one-off tests.)r9   ÚdescÚreusezŒReuse the previous token cache {} (if any) which was created during last test app exit. Useful for testing acquire_token_silent() repeatedlyc                 ó   — | d   S )Nr©   r   r`   s    r   r   z_main.<locals>.<lambda>ò   ó
   €  ! F¡)€ r   z1What token cache state do you want to begin with?F)r4   r2   r5   r9   Úrz+Azure CLI (Correctly configured for MSA-PT))ro   Únamez/Visual Studio (Correctly configured for MSA-PT)z$95de633a-083e-42f5-b444-a4295d8e9314zAWhiteboard Services (Non MSA-PT app. Accepts AAD & MSA accounts.)Ú	CLIENT_IDÚCLIENT_SECRETzoA confidential client app (CCA) whose settings are defined in environment variables CLIENT_ID and CLIENT_SECRET)ro   Úclient_secretr®   c                 ó   — | d   S )Nr®   r   rH   s    r   r   z_main.<locals>.<lambda>  r¬   r   zUImpersonate this app (or you can type in the client_id of your own public client app)Tr±   ro   zAYou need to set environment variables CLIENT_ID and CLIENT_SECRETzYEnable broker? (It will error out later if your app has not registered some redirect URI)zEnable PII in broker's log?)z(https://login.microsoftonline.com/commonz/https://login.microsoftonline.com/organizationsz;https://login.microsoftonline.com/microsoft.onmicrosoft.comz:https://login.microsoftonline.com/msidlab4.onmicrosoft.comz+https://login.microsoftonline.com/consumerszKInput authority (Note that MSA-PT apps would NOT use the /common authority)r>   z!https://login.microsoftonline.comz�You input an unusual authority which might fail the Instance Discovery. Now, do you want to perform Instance Discovery on your input authority?)Ú	authorityÚinstance_discoveryÚenable_broker_on_windowsÚenable_broker_on_macÚenable_broker_on_linuxÚenable_broker_on_wslÚenable_pii_logÚtoken_cache)Úclient_credentialr³   r´   r¹   rº   c                 ó   — | j                   S ©N)Ú__doc__)r    s    r   r   z_main.<locals>.<lambda>E  s
   €  a§i¡i€ r   zMSAL Python APIs:rJ   zInvalid input: %sÚAbortedz	Error: %s)(r   r#   rj   Ú__version__r:   r   ÚosÚpathÚexistsr   Údeserializer   ÚreadÚIOErrorrp   rq   Úgetenvri   rl   r0   r%   Úenable_debug_logÚ
startswithrk   r›   rY   rx   r…   r�   r’   r–   r}   r™   r�   r    r¦   rs   r�   ÚKeyboardInterruptÚ	Exception)Úcache_choiceÚ
chosen_appÚis_ccaÚenable_brokerr¹   r³   r´   rL   Úmethods_to_be_testedÚfuncÚes              r   Ú_mainrÓ   ã   s5  € Ü	Ð
A×
HÑ
HÌ×IYÑIYÓ
ZÔ[Ü"à!ØVñð
 "ðKçKQÉ6Ü-óL/ñ	ð$
ñ ,ØBØ$ô&€Lð  �HÑ Ò(¬R¯W©W¯^©^Ô<QÔ-Rð	Ü×$Ñ$¤TÔ*?ÀÓ%E×%JÑ%JÓ%LÔMô !Ü Ð*WÑXÜ$Ð._Ñ`Ø<ð  GJñ  	KäŸ™ ;Ó/ÜŸY™Y Ó7ðGñ	
ð	
"
ñ ,ðOà#ô%€Jô ˜
¤DÓ)ÒK¨oÀÐ.K€FÙ�z +Ò.°:¸oÒ3NÜÐ\Ó]Ð]Ø�Zò 
¤^ð 5Uó &
€Mñ GTÕXh”^Ð$AÔBÐns€NÜò !
ð ]Ø#ô	
€Iñ ˜y×3Ñ3Ø/ô 1ô (ð	Rô
ð 7;ð	 ñ ô ×
&Ñ
&Ü#-¨j¼$Ô#?ˆ
�;ÒÀZØØ-Ø!.Ø*Ø,Ø*Ø%Ü õ

ô "×?Ñ?Ø�;ÑØ$ _Ñ5ØØ-Ø%Ü ô
ð ô& "ð
ô ˜C¤×!=Ñ!=Ô>ô 'Ü)Ü&Ü)Ü*ñð EGñ	
ô 0Üð
ñ
ô ˜C¤×!CÑ!CÔDô &Ü%ñð KMñ
Ðð" ÜØ ¤E 7Ñ*Ù/Ð8KôMˆð	*Ù�ŒIð øôU ò 	Úð	ûô` ò 	2Ü�M‰MÐ-¨q×1Ñ1ûÜ ò 	Ü�)ÖÜò 	*Ü�M‰M˜+ q×)Ñ)ûð	*ús<   Â 1I7 É.J É7	JÊJÊ	K,ÊJ+Ê+K,ËK,ËK'Ë'K,Ú__main__r½   )NN)2r¾   Úbase64r{   r   rs   r€   rÁ   Úatexitrj   r   ÚSerializableTokenCacher   Úregisterrp   rq   ÚPopAuthSchemeÚHTTP_GETrW   r   r%   r)   Ústrr:   rÈ   ÚbasicConfigÚDEBUGÚINFOÚdotenvr<   ÚinfoÚImportErrorrt   rC   rN   rY   rx   r}   r…   Ú_JWK1rŽ   r�   r�   r’   r–   r™   r�   r    r¦   rÓ   Ú__name__r   r   r   ú<module>rä      s�  ðñ÷ =× <× <× <à(Ð Ø*ˆt×*Ñ*Ó,€Ø €‡�ñ 0ô ð 4€
Ø7€Ø,˜$×,Ñ,Ø×"Ñ"×+Ñ+Ø&Ø
ôÐ ò6ò*ó
Eð (Ð0CÐUXØ$ó ñ* "Ð"CÓDÐ Ø €× Ñ Ñ+;˜'Ÿ-š-ÀÇÁÕ Nð?Ý"Ù„MØ€G‡L�LÐ>Ô?òò	dòó%òNVò
ð 	F€Ø *°fÈÑO€ØIÐJ€ò<ò7ò7ònòEò
#ò
òj*ðX ˆzÒÙ	…Gð øðU ò ?Ø€G‡O�Oð	>ö?ð?ús   Â<D ÄD9Ä8D9