
    qhO                     >    S r SSKrSSKJr  SSKJr   " S S\5      rg)	z.
OAuth2 Backend to work with microsoft graph.
    N   )AuthMissingParameter   )
BaseOAuth2c                   R    \ rS rSrSrSrSrSrSrS/r	S r
S	 rS
 rS rS rS rSrg)MicrosoftOAuth2   zmicrosoft-graph z>https://login.microsoftonline.com/common/oauth2/v2.0/authorizez:https://login.microsoftonline.com/common/oauth2/v2.0/tokenFz	User.Readc                 \   U R                  U R                  5        U R                  5       nU R                  U R	                  5       U R                  U5      U R                  5       U R                  5       U R                  S9nU R                  U5        U R                  " US   /UQ7SU0UD6$ )z2Completes login process, must return user instance)dataheadersauthmethodaccess_tokenresponse)
process_errorr   validate_staterequest_access_tokenaccess_token_urlauth_complete_paramsauth_headersauth_complete_credentialsACCESS_TOKEN_METHODdo_auth)selfargskwargsstater   s        P/var/www/html/env/lib/python3.13/site-packages/social_core/backends/microsoft.pyauth_completeMicrosoftOAuth2.auth_complete   s    499%##%,,!!#**51%%'//1++ - 
 	8$||^$
:>
/7
BH
 	
    c                 $    UR                  S5      $ )z Use user account id as unique idid)get)r   detailsr   s      r   get_user_idMicrosoftOAuth2.get_user_id&   s    ||D!!r"   c                 $   UR                  S5      nUR                  S5      nU(       d  [        U S5      eSU;   a  U(       d  UnUR                  SS5      S   nUUUR                  SS5      UR                  SS5      UR                  S	S5      S
.$ )z1Return user details from Microsoft online accountmailuserPrincipalName@r   r   displayName 	givenNamesurname)usernameemailfullname
first_name	last_name)r%   r   split)r   r   r2   r1   s       r   get_user_details MicrosoftOAuth2.get_user_details*   s    V$<< 34&t-@AA(? ~~c1-a0H ! ]B7",,{B7!i4
 	
r"   c                 2    U R                  SSSSU-   S.SS9$ )z.Return user data by querying Microsoft servicez#https://graph.microsoft.com/v1.0/mez!application/x-www-form-urlencodedzapplication/jsonzBearer )zContent-TypeAcceptAuthorizationGET)r   r   )get_json)r   r   r   r   s       r   	user_dataMicrosoftOAuth2.user_data?   s3    }}1 C,!*\!9
   
 	
r"   c                 L    U R                  S5      U R                  S5      USS.$ )NKEYSECRETrefresh_token)	client_idclient_secretrC   
grant_type)setting)r   tokenr   r   s       r   refresh_token_params$MicrosoftOAuth2.refresh_token_paramsK   s*    e,!\\(3")	
 	
r"   c                     U R                  US9nUR                  R                  nUR                  R                  S   nU[	        [
        R
                  " 5       5      ::  a  U R                  US9nUS   nU$ )zkReturn the access token for the given user, after ensuring that it
has not expired, or refreshing it if so.)user_id
expires_on)rH   r   )get_usersocial_userr   
extra_datainttimerC   )r   rL   userr   rM   new_token_responses         r   get_auth_tokenMicrosoftOAuth2.get_auth_tokenS   sr     }}W}-''44%%00>
TYY[))!%!3!3,!3!G-n=Lr"    N)__name__
__module____qualname____firstlineno__nameSCOPE_SEPARATORAUTHORIZATION_URLACCESS_TOKEN_URLREDIRECT_STATEDEFAULT_SCOPEr    r'   r7   r>   rI   rU   __static_attributes__rW   r"   r   r   r      sB    DOXSN MM
$"
*


	r"   r   )__doc__rR   
exceptionsr   oauthr   r   rW   r"   r   <module>rf      s#     - Qj Qr"   