
    Tњh                     8   S SK r S SKJr  S SKJrJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJrJrJr  S SKJrJr  SSKJr  SSKJr   " S S\5      r\\SS j5       5       r \RB                  " \5      r"\ r#\RB                  " \5      r$g)    N)	timedelta)HttpResponseNotAllowedHttpResponseRedirect)reverse)timezone)	urlencode)csrf_exempt)login_not_required)jwtkit)SocialToken)OAuth2AdapterOAuth2CallbackViewOAuth2LoginView)build_absolute_uriget_request_param   )get_apple_session)AppleOAuth2Clientc                   T    \ rS rSr\rSrSrSrSr	\
S 5       rS rS rS	 rSS jrSrg
)AppleOAuth2Adapter   applez$https://appleid.apple.com/auth/tokenz(https://appleid.apple.com/auth/authorizez#https://appleid.apple.com/auth/keysc                     [         R                  " UU R                  SUR                  5       [         R                  S9nU$ )Nzhttps://appleid.apple.com)
credentialkeys_urlissueraudience
lookup_kid)r   verify_and_decodepublic_key_urlget_audslookup_kid_jwk)clsproviderid_tokendatas       fD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/socialaccount/providers/apple/views.pyget_verified_identity_data-AppleOAuth2Adapter.get_verified_identity_data   s=    ''''.&&(,,
     c                 N   [        US   S9nUR                  SS5      Ul        UR                  U R                  5      nU(       a-  [        R
                  " 5       [        [        U5      S9-   Ul        [        R                  U R                  5       US   5      n0 UEUEUl        U$ )Naccess_token)tokenrefresh_token )secondsr%   )r   gettoken_secretexpires_in_keyr   nowr   int
expires_atr   r(   get_provider	user_data)selfr&   r-   
expires_inidentity_datas        r'   parse_tokenAppleOAuth2Adapter.parse_token*   s    ~&
 "XXor:XXd112
'||~	#j/0RRE +EEj!1
 4T3]3r*   c                     UR                   nU R                  5       R                  XS9nUR                   UR                  S'   [	        U5      R                  5         U$ )N)requestresponser%   )r8   r7   sociallogin_from_responsestater   delete)r9   r?   appr-   kwargs
extra_datalogins          r'   complete_login!AppleOAuth2Adapter.complete_login=   sX    __
!!#== > 
 #(//J 	'"))+r*   c                     UR                   R                  SS5      n [        R                  " U5      $ ! [        R                   a    0 s $ f = f)Nuserr/   )apple_login_sessionr1   jsonloadsJSONDecodeError)r9   r?   user_scope_datas      r'   get_user_scope_data&AppleOAuth2Adapter.get_user_scope_dataI   sJ    !5599&"E	::o..## 	 I	s   4 AANc                     [        U5      n[        US5      nUR                  XdS9nUR                  SS5      nUc  UR                  R                  S5      n0 UEU R                  U5      ESU0E$ )z8We need to gather the info from the apple specific logincode)pkce_code_verifierr%   N)r   r   get_access_tokenr1   storerQ   )	r9   r?   rD   clientrU   apple_sessionrT   access_token_datar%   s	            r'   get_access_token_data(AppleOAuth2Adapter.get_access_token_dataR   s    )'2 !&1"33 4 
 %((T:$**..z:H

&&w/
 
 	
r*    )N)__name__
__module____qualname____firstlineno__r   client_classprovider_idaccess_token_urlauthorize_urlr    classmethodr(   r<   rH   rQ   r[   __static_attributes__r]   r*   r'   r   r      sB    $LK=>M:N &

r*   r   c                    U R                   S:w  a  [        S/5      $ [        U 5      n/ SQn0 nU H  n[        XS5      nU(       d  M  XdU'   M     SS/nU H  n[        XS5      UR                  U'   M     [        U [        U5      5      n[        SR                  U[        U5      S95      n	UR                  U	5        U	$ )a  
Apple uses a `form_post` response type, which due to
CORS/Samesite-cookie rules means this request cannot access
the request since the session cookie is unavailable.

We work around this by storing the apple response in a
separate, temporary session and redirecting to a more normal
oauth flow.

args:
    finish_endpoint_name (str): The name of a defined URL, which can be
        overridden in your url configuration if you have more than one
        callback endpoint.
POST)rT   rB   errorr/   rK   r%   z{url}?{query})urlquery)methodr   r   r   rW   r   r   r   formatr   save)
r?   finish_endpoint_namerY   keys_to_put_in_url
url_paramskeyvaluekeys_to_save_to_sessionrk   r@   s
             r'   apple_post_callbackrv   h   s    " ~~%vh//%g.M 4J!!'35#sO "  &z2&#4W2#FC  ' Wg.B&C
DC#3i
.CDH x Or*   )apple_finish_callback)%rM   datetimer   django.httpr   r   django.urlsr   django.utilsr   django.utils.httpr   django.views.decorators.csrfr	   #allauth.account.internal.decoratorsr
   allauth.socialaccount.internalr   allauth.socialaccount.modelsr   ,allauth.socialaccount.providers.oauth2.viewsr   r   r   allauth.utilsr   r   rY   r   rX   r   r   rv   adapter_viewoauth2_loginoauth2_callbackoauth2_finish_loginr]   r*   r'   <module>r      s      D  ! ' 4 B 1 4 
 @ , %M
 M
` %  %P ++,>?%(556HI r*   