Ë
    ûûàgÇ  ã                   ó6  — d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZ d dlmZmZ ddlmZ ddlmZ  G d„ de«      Zeedd„«       «       Z  ejB                  e«      Z"e Z# ejB                  e«      Z$y)é    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                   óJ   — e Zd ZeZdZdZdZdZe	d„ «       Z
d„ Zd„ Zd„ Zdd
„Zy	)ÚAppleOAuth2AdapterÚapplez$https://appleid.apple.com/auth/tokenz(https://appleid.apple.com/auth/authorizez#https://appleid.apple.com/auth/keysc                 ó†   — t        j                  || j                  d|j                  «       t         j                  ¬«      }|S )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       úi/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/allauth/socialaccount/providers/apple/views.pyÚget_verified_identity_dataz-AppleOAuth2Adapter.get_verified_identity_data   s=   € ä×'Ñ'ØØ×'Ñ'Ø.Ø×&Ñ&Ó(Ü×,Ñ,ô
ˆð ˆó    c                 óN  — t        |d   ¬«      }|j                  dd«      |_        |j                  | j                  «      }|r/t	        j
                  «       t        t        |«      ¬«      z   |_        t        j                  | j                  «       |d   «      }i |¥|¥|_        |S )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_tokenzAppleOAuth2Adapter.parse_token*   s™   € ÜØ�~Ñ&ô
ˆð "ŸX™X o°rÓ:ˆÔà—X‘X˜d×1Ñ1Ó2ˆ
ÙÜ'Ÿ|™|›~´	Ä#ÀjÃ/Ô0RÑRˆEÔô +×EÑEØ×ÑÓ  jÑ!1ó
ˆð 4˜TÐ3 ]Ð3ˆŒàˆr(   c                 óÄ   — |j                   }| j                  «       j                  ||¬«      }|j                   |j                  d<   t	        |«      j                  «        |S )N)ÚrequestÚresponser$   )r6   r5   Úsociallogin_from_responseÚstater   Údelete)r7   r<   Úappr+   ÚkwargsÚ
extra_dataÚlogins          r&   Úcomplete_loginz!AppleOAuth2Adapter.complete_login=   sZ   € Ø—_‘_ˆ
Ø×!Ñ!Ó#×=Ñ=Ø jð >ó 
ˆð #(§/¡/ˆ�‰�JÑô 	˜'Ó"×)Ñ)Ô+Øˆr(   c                 óœ   — |j                   j                  dd«      }	 t        j                  |«      S # t        j                  $ r i cY S w xY w)NÚuserr-   )Úapple_login_sessionr/   ÚjsonÚloadsÚJSONDecodeError)r7   r<   Úuser_scope_datas      r&   Úget_user_scope_dataz&AppleOAuth2Adapter.get_user_scope_dataI   sJ   € Ø!×5Ñ5×9Ñ9¸&À"ÓEˆð	Ü—:‘:˜oÓ.Ð.øÜ×#Ñ#ò 	ð ŠIð	ús   ž3 ³AÁ
ANc                 óæ   — t        |«      }t        |d«      }|j                  ||¬«      }|j                  dd«      }|€|j                  j                  d«      }i |¥| j                  |«      ¥d|i¥S )z8We need to gather the info from the apple specific loginÚcode)Úpkce_code_verifierr$   N)r   r   Úget_access_tokenr/   ÚstorerM   )	r7   r<   rA   ÚclientrP   Úapple_sessionrO   Úaccess_token_datar$   s	            r&   Úget_access_token_dataz(AppleOAuth2Adapter.get_access_token_dataR   s—   € ä)¨'Ó2ˆô ! ¨&Ó1ˆØ"×3Ñ3ØÐ%7ð 4ó 
Ðð %×(Ñ(¨°TÓ:ˆàÐØ$×*Ñ*×.Ñ.¨zÓ:ˆHð
Øð
à×&Ñ& wÓ/ð
ð ˜ñ
ð 	
r(   )N)Ú__name__Ú
__module__Ú__qualname__r   Úclient_classÚprovider_idÚaccess_token_urlÚauthorize_urlr   Úclassmethodr'   r:   rE   rM   rV   © r(   r&   r   r      sB   „ Ø$€LØ€KØ=ÐØ>€MØ:€Nàñó ðòò&
òô
r(   r   c                 óv  — | j                   dk7  rt        dg«      S t        | «      }g d¢}i }|D ]  }t        | |d«      }|sŒ|||<   Œ ddg}|D ]  }t        | |d«      |j                  |<   Œ t        | t        |«      «      }t        dj                  |t        |«      ¬«      «      }	|j                  |	«       |	S )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)rO   r?   Úerrorr-   rG   r$   z{url}?{query})ÚurlÚquery)Úmethodr   r   r   rR   r   r   r   Úformatr   Úsave)
r<   Úfinish_endpoint_namerT   Úkeys_to_put_in_urlÚ
url_paramsÚkeyÚvalueÚkeys_to_save_to_sessionrc   r=   s
             r&   Úapple_post_callbackrn   h   sß   € ð" ‡~�~˜ÒÜ% v hÓ/Ð/Ü% gÓ.€Mò 4ÐØ€JØ!ò $ˆÜ! '¨3°Ó3ˆÚØ#ˆJ�sŠOð$ð  & zÐ2ÐØ&ò GˆÜ#4°W¸cÀ2Ó#Fˆ×Ñ˜CÒ ðGô ˜W¤gÐ.BÓ&CÓ
D€CÜ#Ø×Ñ 3¬i¸
Ó.CÐÓDó€Hð ×Ñ�xÔ Ø€Or(   )Úapple_finish_callback)%rI   Ú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   rT   r   rS   r   r   rn   Úadapter_viewÚoauth2_loginÚoauth2_callbackÚoauth2_finish_loginr_   r(   r&   ú<module>r      s”   ðÛ Ý ç DÝ Ý !Ý 'Ý 4å BÝ 1Ý 4÷ñ ÷
 @å ,Ý %ôM
˜ô M
ð` Øò%ó ó ð%ðP ,ˆ×+Ñ+Ð,>Ó?€Ø%€Ø5Ð(×5Ñ5Ð6HÓIÑ r(   