
    Sњh;                        S SK Jr  S SKJr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Jr  S SKJrJrJr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&  S SK'J(r(  S SK)J*r*  S SK+J,r,J-r-  S SK.J/r0  S SK1J2r2  S SK3J4r4  S SK5J6r6  S SK7J8r8J9r9  S SK:J/r/  S SK;J<r<  S SK=J>r>J?r?J@r@  S SKAJBrB  S SKCJDrDJErE  S SKFJGrGJHrHJIrIJJrJ  S SKKJLrL  S SKMJNrN  \" \2S S!9 " S" S#\"5      5       rO\OR                  5       rQ\" \$S S!9\" \&S S!9\" \2S S!9 " S$ S%\(5      5       5       5       rR\RR                  5       rS\" \&S S!9\" \2S S!9 " S& S'\"5      5       5       rT\TR                  5       rU\" \&S S!9\" \	S S!9 " S( S)\"5      5       5       rV\VR                  5       rW\" \&S S!9\" \2S S!9 " S* S+\"5      5       5       rX\XR                  5       rY\" \2S S!9 " S, S-\"5      5       rZ\ZR                  5       r[\" \2S S!9 " S. S/\"5      5       r\\\R                  5       r]\" \&S S!9\" \2S S!9 " S0 S1\"5      5       5       r^\^R                  5       r_g2)3    )
HTTPStatus)ListOptional)REDIRECT_FIELD_NAMEget_user_model)login_required)get_current_site)PermissionDenied)BadSignatureSigner)HttpRequestHttpResponseHttpResponseForbiddenHttpResponseRedirectJsonResponse)CsrfViewMiddleware)render)reverse)method_decorator)	urlencode)View)xframe_options_deny)csrf_exempt)FormView)errors)InvalidScopeErrorOAuth2Error)app_settings)login_not_required)str_to_user_id)jwkkit)add_query_paramsdel_query_params)get_adapter)AuthorizationFormConfirmCodeFormDeviceAuthorizationForm)device_codes)get_device_server
get_server)convert_responseextract_paramsrespond_html_errorrespond_json_error)Client)build_absolute_uridispatch)namec                   .    \ rS rSrS rS\\   4S jrSrg)ConfigurationView5   c                 p   [        U[        S5      5      [        U[        S5      5      [        U[        S5      5      [        U[        S5      5      [        U[        S5      5      [        U[        S5      5      [        5       R                  5       U R	                  5       S/S/S	.
n[        U5      nS
US'   U$ )Nidp:oidc:authorizationzidp:oidc:device_codezidp:oidc:revokezidp:oidc:tokenzidp:oidc:userinfozidp:oidc:jwkspublicRS256)
authorization_endpointdevice_authorization_endpointrevocation_endpointtoken_endpointuserinfo_endpointjwks_uriissuerresponse_types_supportedsubject_types_supported%id_token_signing_alg_values_supported*Access-Control-Allow-Origin)r0   r   r$   
get_issuer_get_response_types_supportedr   )selfrequestdataresponses       QD:\Anime\Ugyen\janka_web_project\venv\Lib\site-packages\allauth/idp/oidc/views.pygetConfigurationView.get7   s    &8!9:' .@!78. $6!23$ 1'BR:ST!3!45" +7GO4LM!m..0(,(J(J(L(0z6=Y%
(  %25./    returnc                     [        5       n[        R                  R                  S5      R	                  5        H"  nUR                  UR                  5       5        M$     [        [        U5      5      $ )Nresponse_types)	setr/   objectsonlyiteratorupdateget_response_typeslistsorted)rH   rR   clients      rL   rG   /ConfigurationView._get_response_types_supportedP   sT    nn))*:;DDFF!!&";";"=> GF>*++rO    N)	__name__
__module____qualname____firstlineno__rM   r   strrG   __static_attributes__r]   rO   rL   r4   r4   5   s    2,tCy ,rO   r4   c                      ^  \ rS rSr\rS\R                  -   rU 4S jr	U 4S jr
S\\   4S jrS\S\\   S\4S	 jrS
 rS rS\4U 4S jjrS rS rU 4S jrSrU =r$ )AuthorizationViewZ   zidp/oidc/authorization_form.c                   > U R                  U5      nU(       a  U$ [        U R                  5      n [        5       nUR                  " U6 u  U l        U l        SU R                  R                  SS5      ;   a$  UR                  " USU R
                  06n[        U6 $  U R                  S   R"                  R$                  (       a  U R'                  5       $ [(        T	U ]  " U/UQ70 UD6$ ! [        R                   a  n[        X5      s S nA$ S nAf[        R                   a.  n[        UR                  UR                   5      5      s S nA$ S nAff = f)Nnonepromptr]   scopesrI   )_login_requiredr,   rI   r*   validate_authorization_request_scopes_request_inforM   create_authorization_responser+   r   FatalClientErrorr-   r   r   in_uriredirect_urir[   skip_consent_skip_consentsuper)
rH   rI   argskwargsrK   orequestserver	oresponsee	__class__s
            rL   rM   AuthorizationView.geta   s1   ''0O!$,,/	B\F/5/T/T0,DL$, ++//"=="@@&*ll	 (33	 > i(//<<%%''w{74T4V44 && 	2%g11!! 	B'(@AA	Bs0   A)C) )E=
DEE$#EEEc                 B  > UR                   R                  S5      nU(       d2  [        [        S5      S-   UR                   R	                  5       -   5      $ U R                  U5      nU(       a  U$ [        S S9R                  US S0 5      nU(       a  [        SU 35      $  [        5       nUR                  U5      u  U l        U l        UR                   R                  S5      S	:w  a  U R                  5       $ [         TU ]D  " U/UQ70 UD6$ ! [         a    [        ef = f)
NrI   r7   ?c                     g Nr]   )reqs    rL   <lambda>(AuthorizationView.post.<locals>.<lambda>   s    TrO   )get_responser]   zCSRF Failed: actiongrant)POSTrM   r   r   r   rk   r   process_viewr   r   unsign_objectrm   rn   r   r
   _respond_with_access_deniedru   post)	rH   rI   rv   rw   signed_request_inforK   reasonsignerr|   s	           rL   r   AuthorizationView.postz   s   %ll..y9"'01C7',,:P:P:RR  ''0O $1ABOOT2r
 (=)ABB	#XF/5/C/CDW/X,DL$, <<H%03355w|G5d5f55	  	#""	#s   "(D DrP   c                 
   / nUR                   R                  S5      nU(       a  UR                  5       nSU;   a  U R                  X5      $ SU;   a  g UR                  R
                  (       a  g [        5       " S 5      " U5      $ )Nri   loginrh   )GETrM   split_handle_login_promptuseris_authenticatedr   )rH   rI   promptsri   s       rL   rk   !AuthorizationView._login_required   sn    *llnGg,,W>>W<<((%g..rO   rI   r   c                 2   UR                  S5        UR                  5       nU(       a  [        USSR                  U5      05      nO[	        US5      n0 nX4[
        '   [        UR                  R                  (       a  SOS5      n[        [        XT5      5      $ )Nr   ri    account_reauthenticateaccount_login)
removeget_full_pathr"   joinr#   r   r   r   r   r   )rH   rI   r   next_urlparamspaths         rL   r   &AuthorizationView._handle_login_prompt   s     	w((*'8SXXg=N2OPH'(;H&."#||,, % 

 $$4T$BCCrO   c                     U R                   S   R                  nU R                  5       nUSS.US'   U R                  " S0 UD6nUR	                  5       (       d
  [        5       eU R                  U5      $ )NrI   znot-relevant-for-skip-consent)rj   rI   rJ   r]   )rn   rj   get_form_kwargs
form_classis_validr
   
form_valid)rH   rj   form_kwargsforms       rL   rt   AuthorizationView._skip_consent   sn    ##I.55**,6
F --}}"$$t$$rO   c                     U R                   R                  S5      nU R                   R                  S5      nSS0nU(       a  X#S'   [        [        X5      5      $ )Nrr   stateerroraccess_denied)rn   rM   r   r"   )rH   rr   r   r   s       rL   r   -AuthorizationView._respond_with_access_denied   sS    ))--n=""&&w/?+#7O#$4\$JKKrO   c                    > [         TU ]  5       nUR                  U R                  U R                  R
                  S.5        U$ )N)requested_scopesr   )ru   r   rW   rm   rI   r   )rH   retr|   s     rL   r   !AuthorizationView.get_form_kwargs   s4    g%'

dll>O>OPQ
rO   c                    [        5       n0 nU R                  nUR                  SS 5        UR                  S5      n[	        U[
        5      (       a  [        U5      US'   UR                  U R                  U45      US'   U$ )NrI   ri   )	r   rn   poprM   
isinstancerS   rY   sign_objectrm   )rH   r   r   request_infori   s        rL   get_initialAuthorizationView.get_initial   sv    ))D)!!(+fc""%)&\L"++T\\<,HII
rO   c                    [        U R                  5      nUR                  S   nSU R                  R                  0nUR	                  U R
                  5         UR                  R                  S5      nU(       a  XTS'   [        5       R                  " X#US.6n[        U6 $ ! [        R                   a   n[        U R                  U5      s S nA$ S nAff = f)Nrj   r   email)rj   credentials)r,   rI   cleaned_datar   rW   rn   rM   r*   ro   r+   r   rp   r-   )rH   r   rx   rj   r   r   rz   r{   s           rL   r   AuthorizationView.form_valid   s    !$,,/""8,t||0014--.
	7%%))'2E',G$"BBkI $Y//&& 	7%dllA66	7s   AB! !C5C
CCc                    > [         TU ]  " S0 UD6nUR                  [        R                  R                  U R                  S   S9[        U R                  5      S.5        U$ )N	client_idid)r[   siter]   )	ru   get_context_datarW   r/   rT   rM   rn   r	   rI   )rH   rw   r   r|   s      rL   r   "AuthorizationView.get_context_data   sY    g&00

 ..,,0B0B;0O,P(6	
 
rO   )rn   rm   )r^   r_   r`   ra   r%   r   account_settingsTEMPLATE_EXTENSIONtemplate_namerM   r   r   r   rk   r   r   rb   r   rt   r   dictr   r   r   r   rc   __classcell__)r|   s   @rL   re   re   Z   s     #J25E5X5XXM5266/(<*@ /D"D-1#YD	D$%L 
	7" rO   re   c                   &    \ rS rSrS\S\4S jrSrg)DeviceCodeView   rI   rP   c                 ^   [        U5      n [        5       R                  " U6 u  pVnU[        R                  :X  a  UR
                  S   nS n	SUR
                  ;   az  UR
                  S   R                  5       n	[        R                  R                  US9n
[        U	5      R                  [        U
R                  5       5      5      (       d
  [        5       e[        R                  " XU5        [)        XVU5      $ ! [          a)  n[#        UR$                  SUR&                  S9s S nA$ S nAff = f)Nr   scoper   application/jsoncontent_typestatus)r,   r)   $create_device_authorization_responser   OKr   r   r/   rT   rM   rS   issubset
get_scopesr   r(   creater   r   jsonstatus_coder+   )rH   rI   rv   rw   rx   headersrJ   r   r   r   r[   r{   s               rL   r   DeviceCodeView.post   s    !'*	!#HH(S "G6 &#LL5	-1gll*#LL1779E#^^//9/=Fu:..s63D3D3F/GHH/11##Id;
  v66	  	%7 	s   C C9 9
D,D'!D,'D,r]   N)r^   r_   r`   ra   r   r   r   rc   r]   rO   rL   r   r      s    7K 7\ 7rO   r   c                   0    \ rS rSrS rS\S\S\4S jrSrg)	DeviceAuthorizationViewi  c                 N   SUR                   ;   a`  [        UR                   5      nUR                  5       (       a5  U R                  UUR                  S   UR
                  UR                  5      $ O
[        5       nU[        S5      S.n[        US[        R                  -   U5      $ )Ncodeidp:oidc:device_authorization)r   autorization_urlz(idp/oidc/device_authorization_code_form.)r   r&   r   _dispatch_authorizationr   device_coder[   r   r   r   r   )rH   rI   rv   rw   r   contexts         rL   r1    DeviceAuthorizationView.dispatch  s    W[[ "7;;/D}}33%%f-$$KK	   #$D '(G H
 6112	
 	
rO   	user_coder   r[   c                    X$S.nUR                   S:X  a  [        UR                  5      nUR                  5       (       a[  UR                  S   S:H  n[
        R                  " UR                  X7S9  U(       a  SnOSn[        UU[        R                  -   U5      $ O
[        5       n[        S5      S	-   [        S
U05      -   US'   [        US[        R                  -   U5      $ )N)r   r[   r   r   confirm)r   z(idp/oidc/device_authorization_confirmed.z%idp/oidc/device_authorization_denied.r   r   r   r   z+idp/oidc/device_authorization_confirm_form.)methodr'   r   r   r   r(   confirm_or_deny_device_coder   r   r   r   r   r   )	rH   rI   r   r   r[   r   r   r   r   s	            rL   r   /DeviceAuthorizationView._dispatch_authorization.  s     !*<>>V#*7<<8D}}++H5B88LL+ $NM$KM!$4$G$GG   +,D34+,- 	"# 9112	
 	
rO   r]   N)	r^   r_   r`   ra   r1   rb   r/   r   rc   r]   rO   rL   r   r     s$    
.!
"%!
47!
AG!
rO   r   c                   L    \ rS rSrS rS	S\\   4S jjrS\\   4S jrS r	Sr
g)
	TokenViewiU  c                     UR                   R                  S5      [        R                  R                  :X  a  U R                  U5      $ U R                  U5      $ )N
grant_type)r   rM   r/   	GrantTypeDEVICE_CODE_post_device_token_create_token_response)rH   rI   s     rL   r   TokenView.postY  sG    <<L)V-=-=-I-II**733**733rO   NrJ   c                 d   ^ ^ [        U5      n[        UU 4S j/S9R                  " U6 n[        U6 $ )Nc                 (   > TR                  U T5      $ r   )
_pre_token)rx   rJ   rH   s    rL   r   2TokenView._create_token_response.<locals>.<lambda>a  s    $(GrO   )	pre_token)r,   r*   create_token_responser+   )rH   rI   rJ   rx   rz   s   ` `  rL   r    TokenView._create_token_response^  s=    !'*GH


 !)+	  ++rO   c                     UR                   [        R                  R                  :X  aV  Uc   eUR	                  S5      =n(       a  X1l        [        5       R                  R	                  [        US   5      S9Ul	        g g )Nr   r   )pk)
r   r/   r   r   rM   r   r   rT   r    r   )rH   rx   rJ   r   s       rL   r   TokenView._pre_tokene  sr    &"2"2">">>###))u)!&*,4488!$v,/ 9 HM	 ?rO   c                      [         R                  " U5      nU R                  X5      $ ! [         a)  n[	        UR
                  SUR                  S9s S nA$ S nAff = f)Nr   r   )r(   poll_device_coder   r   r   r   r   )rH   rI   rJ   r{   s       rL   r   TokenView._post_device_tokenn  sY    	>009D ..w==  	%7 	s   ) 
AAAAr]   r   )r^   r_   r`   ra   r   r   r   r   r   r   rc   r]   rO   rL   r   r   U  s,    4
,HTN ,$ >rO   r   c                       \ rS rSrS rSrg)UserInfoViewi|  c                     [        U5      n [        5       R                  " U6 n[        U6 $ ! [         a  n[        X5      s S nA$ S nAff = fr   )r,   r*   create_userinfo_responser+   r   r.   )rH   rI   rx   rz   r{   s        rL   rM   UserInfoView.get  sI    !'*	2"==xHI#Y// 	2%g11	2s   , 
A
A AAr]   Nr^   r_   r`   ra   rM   rc   r]   rO   rL   r  r  |  s    2rO   r  c                       \ rS rSrS rSrg)JwksViewi  c                     / n[         R                  4 H,  n[        R                  " U5      u  pgUR	                  U5        M.     [        SU05      nSUS'   U$ )NkeysrD   rE   )r   PRIVATE_KEYr!   load_jwk_from_pemappendr   )	rH   rI   rv   rw   r  pemjwk_rK   s	            rL   rM   JwksView.get  sX     ,,-C--c2FCKK .  /25./rO   r]   Nr  r]   rO   rL   r  r    s    rO   r  c                       \ rS rSrS rSrg)
RevokeViewi  c                 V    [        U5      n[        5       R                  " U6 n[        U6 $ r   )r,   r*   create_revocation_responser+   )rH   rI   rv   rw   rx   rz   s         rL   r   RevokeView.post  s)    !'*L;;XF	++rO   r]   N)r^   r_   r`   ra   r   rc   r]   rO   rL   r  r    s    ,rO   r  N)`httpr   typingr   r   django.contrib.authr   r   django.contrib.auth.decoratorsr   django.contrib.sites.shortcutsr	   django.core.exceptionsr
   django.core.signingr   r   django.httpr   r   r   r   r   django.middleware.csrfr   django.shortcutsr   django.urlsr   django.utils.decoratorsr   django.utils.httpr   django.viewsr   $django.views.decorators.clickjackingr   django.views.decorators.csrfr   django.views.generic.editr   oauthlib.oauth2.rfc6749r   oauthlib.oauth2.rfc6749.errorsr   r   allauth.accountr   r   #allauth.account.internal.decoratorsr    allauth.account.internal.userkitr    allauth.core.internalr!   allauth.core.internal.httpkitr"   r#   allauth.idp.oidcallauth.idp.oidc.adapterr$   allauth.idp.oidc.formsr%   r&   r'   "allauth.idp.oidc.internal.oauthlibr(   )allauth.idp.oidc.internal.oauthlib.serverr)   r*   (allauth.idp.oidc.internal.oauthlib.utilsr+   r,   r-   r.   allauth.idp.oidc.modelsr/   allauth.utilsr0   r4   as_viewconfigurationre   authorizationr   r   r   device_authorizationr   tokenr  	user_infor  jwksr  revoker]   rO   rL   <module>rD     sz    ! C 9 ; 3 4  6 #  4 '  D 4 . * I < B ; ( L ) 0 
 < S  + , $:6, , 7,B "))+ %J7+J/$:6U U 7 0 8Up "))+ +J/$:67T 7 7 07. $$& +J/.z29
d 9
 3 09
x /668  +J/$:6> > 7 0>D 	 $:624 2 72   "	 $:6t  7  +J/$:6, , 7 0, 
			rO   