
    qh                     `    S r SSKrSSKrSSKJrJr  SSKJr   " S S\5      r " S	 S
\5      r	g)a  
Copyright (c) 2015 Microsoft Open Technologies, Inc.

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Azure AD OAuth2 backend, docs at:
    https://python-social-auth.readthedocs.io/en/latest/backends/azuread.html
    N   )AuthMissingParameterAuthTokenError   )
BaseOAuth2c                      ^  \ rS rSrSrSrSrSrSrSr	/ SQr
/ S	Qr\S
 5       r\S 5       r\S 5       rS rS rS rS rS rU 4S jrSU 4S jjrS rS rSrU =r$ )AzureADOAuth2&   zazuread-oauth2 z$https://{authority_host}/{tenant_id}z{base_url}/oauth2/authorizez{base_url}/oauth2/tokenF)openidprofileuser_impersonationemail)	)access_tokenr   )id_tokenr   )refresh_tokenr   )
expires_inexpires)
expires_onr   )
not_beforer   )
given_name
first_name)family_name	last_name)
token_typer   c                 &    U R                  SS5      $ )NAUTHORITY_HOSTzlogin.microsoftonline.comsettingselfs    N/var/www/html/env/lib/python3.13/site-packages/social_core/backends/azuread.pyauthority_hostAzureADOAuth2.authority_host:   s    ||,.IJJ    c                     g)Ncommon r    s    r"   	tenant_idAzureADOAuth2.tenant_id>   s    r%   c                 ^    U R                   R                  U R                  U R                  S9$ )N)r#   r)   )BASE_URLformatr#   r)   r    s    r"   base_urlAzureADOAuth2.base_urlB   s-    }}##..$.. $ 
 	
r%   c                 H    U R                   R                  U R                  S9$ N)r.   )AUTHORIZATION_URLr-   r.   r    s    r"   authorization_urlAzureADOAuth2.authorization_urlH   s     %%,,dmm,DDr%   c                 H    U R                   R                  U R                  S9$ r1   )ACCESS_TOKEN_URLr-   r.   r    s    r"   access_token_urlAzureADOAuth2.access_token_urlK   s     $$++T]]+CCr%   c                 F    UR                  S5      nUc  [        U S5      eU$ )zUse upn as unique idupn)getr   )r!   detailsresponser:   s       r"   get_user_idAzureADOAuth2.get_user_idN   s'    ll5!;&tU33
r%   c                     UR                  SS5      UR                  SS5      UR                  SS5      pCnUUR                  SUR                  S5      5      UUUS.$ )z)Return user details from Azure AD accountname r   r   r   r:   )usernamer   fullnamer   r   )r;   )r!   r=   rD   r   r   s        r"   get_user_detailsAzureADOAuth2.get_user_detailsU   sd     LL$LLr*LL+ ( !\\'8<<+>? $"
 	
r%   c                 (   UR                  S5      nU(       a(  UR                  S5      (       a  UR                  S5      nOUn [        R                  " USS0S9nU$ ! [        R                  [        R                  4 a  n[        X5      eS nAff = f)Nr=   r   verify_signatureF)options)r;   jwtdecodeDecodeErrorExpiredSignatureErrorr   )r!   r   argskwargsr=   r   decoded_id_tokendes           r"   	user_dataAzureADOAuth2.user_datad   s    ::j)Z00||J/H#H	+"zz(=OQV<WX   !:!:; 	+ **	+s   A $BBBc                 z   > [         TU ]  5       nU R                  S5      nU(       a  UR                  SU05        U$ )z`Return extra arguments needed on auth process. The defaults can be
overridden by GET parameters.RESOURCEresource)superauth_extra_argumentsr   update)r!   extra_argumentsrV   	__class__s      r"   rX   "AzureADOAuth2.auth_extra_argumentsq   s<      '68<<
+""J#9:r%   c                 Z   > [         TU ]  " XX4/UQ70 UD6nU R                  S5      US'   U$ )zHReturn access_token and extra defined names to store in
extra_data fieldrU   rV   )rW   
extra_datar   )	r!   useruidr=   r<   rN   rO   datar[   s	           r"   r^   AzureADOAuth2.extra_dataz   s8     w!$XPPP<<
3Zr%   c                 l    U R                  S5      U R                  S5      USU R                  S5      S.$ )NKEYSECRETr   rU   )	client_idclient_secretr   
grant_typerV   r   )r!   tokenrN   rO   s       r"   refresh_token_params"AzureADOAuth2.refresh_token_params   s6    e,!\\(3")Z0
 	
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_idr   )ri   r   )get_usersocial_userr   r^   inttimer   )r!   rm   r_   r   r   new_token_responses         r"   get_auth_tokenAzureADOAuth2.get_auth_token   sr     }}W}-''44%%00>
TYY[))!%!3!3,!3!G-n=Lr%   r(   )N)__name__
__module____qualname____firstlineno__rA   SCOPE_SEPARATORr,   r2   r6   REDIRECT_STATEDEFAULT_SCOPE
EXTRA_DATApropertyr#   r)   r.   r3   r7   r>   rE   rR   rX   r^   rj   rs   __static_attributes____classcell__)r[   s   @r"   r	   r	   &   s    DO5H50NHM
J K K   
 

ED
 
	 	r%   r	   c                   *    \ rS rSrSrSrSrSrS/rSr	g)	AzureADOAuth2V2   zVersion of the AzureADOAuth2 backend that uses the v2.0 API endpoints,
supporting users with personal Microsoft accounts, if the app settings
allow them.zazuread-oauth2-v2z {base_url}/oauth2/v2.0/authorizez{base_url}/oauth2/v2.0/tokenzUser.Read profile openid emailr(   N)
ru   rv   rw   rx   __doc__rA   r2   r6   r{   r~   r(   r%   r"   r   r      s"     D:556Mr%   r   )
r   rq   rJ   
exceptionsr   r   oauthr   r	   r   r(   r%   r"   <module>r      s3   :  
 = mJ m`7m 7r%   