
    TњhK                         S SK r S SKJrJrJr  S SKJr  S SKrS SKJ	r	  S SK
JrJr  S r " S S5      r " S	 S
\5      rg)    N)	parse_qslquote	urlencode)ImproperlyConfigured)get_adapter)OAuth2ClientOAuth2Errorc                  ~    [         R                  " U 0 UD6n[        U[        5      (       a  UR	                  S5      nU$ )Nzutf-8)jwtencode
isinstancebytesdecode)argskwargsresps      gD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/socialaccount/providers/apple/client.py
jwt_encoder      s5    ::t&v&D${{7#K    c                       \ rS rSrSrSrSrg)Scope   emailname N)__name__
__module____qualname____firstlineno__EMAILNAME__static_attributes__r   r   r   r   r      s    EDr   r   c                   4    \ rS rSrSrS rS rS	S jrS rSr	g)
AppleOAuth2Client   z
Custom client because `Sign In With Apple`:
    * requires `response_mode` field in redirect_url
    * requires special `client_secret` as JWT
c                    [        [        R                  " 5       5      n[        U R                  5      R	                  U R                  S5      nUR
                  (       d  [        S5      eUR                  R                  S5      nU(       d  [        S5      eUR
                  SU R                  5       UUS-   S.nU R                  SS	.n[        XCSUS
9nU$ )z6Create a JWT signed with an apple provided private keyapplezApple 'key' missingcertificate_keyzApple 'certificate_key' missingzhttps://appleid.apple.comi  )issaudsubiatexpES256)kidalg)payloadkey	algorithmheaders)inttimer   requestget_appr2   r   settingsgetget_client_idconsumer_secretr   )selfnowappr(   claimsr4   client_secrets          r   generate_client_secret(AppleOAuth2Client.generate_client_secret    s    $))+$,,'//gFww&'<==,,**+<=&'HII77.%%'=
 ..w?"7G
 r   c                 >    U R                   R                  S5      S   $ )zCWe support multiple client_ids, but use the first one for api calls,r   )consumer_keysplit)r=   s    r   r;   AppleOAuth2Client.get_client_id6   s      &&s+A..r   Nc                    U R                   nU R                  5       nU R                  5       USU R                  US.nU(       a  X%S'   U R	                  U5        [        5       R                  5       R                  U R                  X5U R                  S9nS nUR                  S;   a   UR                  5       nU(       a  SU;  a  [!        SUR"                  -  5      eU$ ! [         a!    [        [        UR                  5      5      n NQf = f)Nauthorization_code)	client_idcode
grant_typeredirect_urirA   code_verifier)datar4   )      access_tokenz!Error retrieving access token: %s)access_token_urlrB   r;   callback_url_strip_empty_keysr   get_requests_sessionr7   access_token_methodr4   status_codejson
ValueErrordictr   textr	   content)r=   rL   pkce_code_verifierurlrA   rP   r   rS   s           r   get_access_token"AppleOAuth2Client.get_access_token:   s    ##335++-. --*
 $6!t$M!!#WT--st||WT 	
 z):#yy{ ~\AADLLPQQ	  :#Idii$89:s   'C (D	D	c                    U R                   R                  [        U5      5      nU R                  5       U R                  SUSS.nU R
                  (       a  U R
                  US'   UR                  U5        U< S[        U[        S9< 3$ )N	form_postzcode id_token)rK   rN   response_modescoperesponse_typestate?)	quote_via)	scope_delimiterjoinsetr;   rU   rh   updater   r   )r=   authorization_urlrf   extra_paramsparamss        r   get_redirect_url"AppleOAuth2Client.get_redirect_urlV   su    $$))#e*5++- --(,
 ::"jjF7Ol#+Yv-OPPr   r   )N)
r   r   r   r   __doc__rB   r;   ra   rr   r"   r   r   r   r$   r$      s    ,/8Qr   r$   )r6   urllib.parser   r   r   django.core.exceptionsr   r   allauth.socialaccount.adapterr   -allauth.socialaccount.providers.oauth2.clientr   r	   r   r   r$   r   r   r   <module>ry      s9     4 4 7 
 5 S 
IQ IQr   