
    lKjLw                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZddlZddlmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddl m!Z! dd	l"m#Z# d
dl$m%Z%m&Z& d
dl'm(Z( ejR                  rddlZ ejT                  d      Z+ejX                  d   Z-e G d d             Z.ddZ/ G d de!      Z0 G d de0      Z1 G d de1      Z2y)zIdentity Provider interface

This defines the _authentication_ layer of Jupyter Server,
to be used in combination with Authorizer for _authorization_.

.. versionadded:: 2.0
    )annotationsN)asdict	dataclass)Morsel)escapehttputilweb)	BoolDictEnumList
TraitErrorTypeUnicodedefaultvalidate)LoggingConfigurable)_i18n   )passwd_checkset_password)get_anonymous_usernamez[^A-Za-z0-9]namedisplay_nameinitials
avatar_urlcolorc                  n    e Zd ZU dZded<   dZded<   dZded<   dZded	<   dZded
<   dZ	ded<   d Z
d Zy)UserziObject representing a User

    This or a subclass should be returned from IdentityProvider.get_user
    strusername r   r   N
str | Noner   r   r   c                $    | j                          y N)fill_defaultsselfs    m/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/jupyter_server/auth/identity.py__post_init__zUser.__post_init__B   s        c                    | j                   sd|  }t        |      | j                  s| j                   | _        | j                  s| j                  | _        yy)zFill out default fields in the identity model

        - Ensures all values are defined
        - Fills out derivative values for name fields fields
        - Fills out null values for optional fields
        z!user.username must not be empty: N)r"   
ValueErrorr   r   )r)   msgs     r*   r'   zUser.fill_defaultsE   sO     }}5dV<CS/! yyDI   $		D !r,   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r+   r'    r,   r*   r    r    *   sO    
 M D#N L#  Hj!J
!E:
*r,   r    c                6   t        | t              rt        |       S t        | t              r@i }d| vrd| v r| d   |d<   t        j                  D ]  }|| v s| |   ||<    	 t        di |S d|  }t        |      # t
        $ r d|  }t        |      dw xY w)a  Backward-compatibility for LoginHandler.get_user

    Prior to 2.0, LoginHandler.get_user could return anything truthy.

    Typically, this was either a simple string username,
    or a simple dict.

    Make some effort to allow common patterns to keep working.
    )r"   r"   r   zUnrecognized user: Nr5   )
isinstancer!   r    dict__dataclass_fields__	TypeErrorr.   )got_userkwargsfieldr/   s       r*   _backward_compat_userr>   Y   s     (C X&&	Hd	#X%&H*<!)&!1F:..E  (u /	,>&>!
 $H:.o  	,'z2CS/t+	,s   "
A= =Bc            	      t   e Zd ZU dZ edd ed            Zded<    ed ed            Z	 e
d	dd ed
            Zded<    ed ed            Z ed ed            j                  d      Zded<    edej"                  d ed            Z edej"                  d ed            Z e e e ej0                  e                  dgd ed            ZdZ ed      d        Z ed      d        Z e
d      Z d ed!<   d=d"Z!d>d#Z"	 	 	 	 	 	 d?d$Z#d@d%Z$dAd&Z%dBd'Z&dCd(Z'dDd)Z(dEd*Z)dFd+Z*dGd,Z+dHd-Z,	 dI	 	 	 	 	 	 	 	 	 dJd.Z-dBd/Z.	 	 	 	 d=d0Z/ e0jb                  d1e0jd                        Z3dKd2Z4d>d3Z5dLd4Z6dMd5Z7dMd6Z8	 dN	 	 	 	 	 dOd7Z9d>d8Z:e;d9        Z<e;d:        Z=e;d;        Z>dPd<Z?y	)QIdentityProvideraC  
    Interface for providing identity management and authentication.

    Two principle methods:

    - :meth:`~jupyter_server.auth.IdentityProvider.get_user` returns a :class:`~.User` object
      for successful authentication, or None for no-identity-found.
    - :meth:`~jupyter_server.auth.IdentityProvider.identity_model` turns a :class:`~jupyter_server.auth.User` into a JSONable dict.
      The default is to use :py:meth:`dataclasses.asdict`,
      and usually shouldn't need override.

    Additional methods can customize authentication.

    .. versionadded:: 2.0
    r#   TzJName of the cookie to set for persisting login. Default: username-${Host}.confighelpzstr | Unicode[str, str | bytes]cookie_nameziExtra keyword arguments to pass to `set_secure_cookie`. See tornado's set_secure_cookie docs for details.NzSpecify whether login cookie should have the `secure` property (HTTPS-only).Only needed when protocol-detection gives the wrong answer due to proxies.)
allow_nonerB   rC   z+bool | Bool[bool | None, bool | int | None]secure_cookieziExtra keyword arguments to pass to `get_secure_cookie`. See tornado's get_secure_cookie docs for details.z<generated>a  Token used for authenticating first-time connections to the server.

        The token can be read from the file referenced by JUPYTER_TOKEN_FILE or set directly
        with the JUPYTER_TOKEN environment variable.

        When no password is enabled,
        the default is to generate a new, random token.

        Setting to an empty string disables authentication altogether, which is NOT RECOMMENDED.

        Prior to 2.0: configured as ServerApp.token
        )rC   )rB   tokenz*jupyter_server.auth.login.LoginFormHandlerz'The login handler class to use, if any.)default_valueklassrB   rC   z(jupyter_server.auth.logout.LogoutHandlerz The logout handler class to use.r   z5List of fields in the User model that can be updated.)traitrH   rB   rC   Fc                   t        j                  d      rd| _        t         j                  d   S t        j                  d      r=d| _        t	        t         j                  d         5 }|j                         cd d d        S | j                  sd| _        yd| _        t        j                  t        j                  d            j                  d      S # 1 sw Y   [xY w)NJUPYTER_TOKENFJUPYTER_TOKEN_FILEr#   T   ascii)osgetenvtoken_generatedenvironopenread
need_tokenbinasciihexlifyurandomdecode)r)   
token_files     r*   _token_defaultzIdentityProvider._token_default   s    99_%#(D ::o..99)*#(D bjj!567:!( 87#(D #'D ##BJJrN3::7CC 87s   (CCupdatable_fieldsc                    t        t        j                  t                    }|d   D cg c]	  }||vs| }}|rd| }t	        |      |d   S c c}w )z7Validate that all fields in updatable_fields are valid.valuez$Invalid fields in updatable_fields: )listtget_argsUpdatableFieldr   )r)   proposalvalid_updatable_fieldsr=   invalid_fieldsr/   s         r*   _validate_updatable_fieldsz+IdentityProvider._validate_updatable_fields   sn     "&ajj&@!A'0
0eEAW4WE0 	 
 88HICS/!  
s
   	AAzbool | Bool[bool, bool | int]rV   c                $    | j                  |      S )zGet the authenticated user for a request

        Must return a :class:`jupyter_server.auth.User`,
        though it may be a subclass.

        Return None if the request is not authenticated.

        _may_ be a coroutine
        )	_get_userr)   handlers     r*   get_userzIdentityProvider.get_user   s     ~~g&&r,   c                  K   t        |dd      r t        j                  d|j                        S | j	                  |      }t        |t        j                        r
| d{   }|}| j                  |      }t        |t        j                        r
| d{   }|}|xs |}| |||k7  r| j                  ||       d|_	        || j                  |      }|j                  |      }|/| j                  j                  d|        | j                  |       | j                  s#| j!                  |      }| j                  ||       |S 7 7 w)Get the user._jupyter_current_userNr    Tz&Clearing invalid/expired login cookie )getattrra   castro   get_user_tokenr7   	Awaitableget_user_cookieset_login_cookie_token_authenticatedget_cookie_name
get_cookielogwarningclear_login_cookieauth_enabledgenerate_anonymous_user)	r)   rk   _token_user
token_user_cookie_usercookie_useruserrD   cookies	            r*   ri   zIdentityProvider._get_user   sO    73T:66&'"?"?@@>B>Q>QRY>Zk1;;/ ++K"-
++G4lAKK0!--L#/ ([
 6 {"%%gt4 ,0G(< ..w7K''4F!  #I+!WX''0$$ 33G< %%gt4I , .s%   AE E!6EEB5EEc                    | j                  |       t        j                  d|j                        }| j	                  ||      }| j                  |       |S )z3Update user information and persist the user model.r    )check_updatera   rq   current_userupdate_user_modelpersist_user_model)r)   rk   	user_datar   updated_users        r*   update_userzIdentityProvider.update_user,  sN     	)$vvfg&:&:;--lIF(r,   c                P    |D ]!  }|| j                   vsd| d}t        |       y)z2Raises if some fields to update are not updatable.zField z is not updatableN)r]   r.   )r)   r   r=   r/   s       r*   r   zIdentityProvider.check_update6  s3    ED111ug%67 o% r,   c                    t         zUpdate user information.NotImplementedError)r)   r   r   s      r*   r   z"IdentityProvider.update_user_model=      !!r,   c                    t         )z'Persist the user model (i.e. a cookie).r   rj   s     r*   r   z#IdentityProvider.persist_user_modelA  r   r,   c                    t        |      S )z"Return a User as an Identity model)r   )r)   r   s     r*   identity_modelzIdentityProvider.identity_modelE  s     d|r,   c                    g }| j                   r|j                  d| j                  f       | j                  r|j                  d| j                  f       |S )zwReturn list of additional handlers for this identity provider

        For example, an OAuth callback handler.
        z/loginz/logout)login_availableappendlogin_handler_classlogout_availablelogout_handler_class)r)   handlerss     r*   get_handlerszIdentityProvider.get_handlersJ  sN    
 OOY(@(@AB  OOZ)B)BCDr,   c           	         t        j                  |j                  |j                  |j                  |j
                  |j                  |j                  d      }|S )zSerialize a user to a string for storage in a cookie

        If overriding in a subclass, make sure to define user_from_cookie as well.

        Default is just the user's username.
        )r"   r   r   r   r   r   )jsondumpsr"   r   r   r   r   r   )r)   r   r   s      r*   user_to_cookiezIdentityProvider.user_to_cookieV  sJ      MM		 $ 1 1 MM"oo	
 r,   c           	     p    t        j                  |      }t        |d   |d   |d   |d   |d   |d         S )zInverse of user_to_cookier"   r   r   r   r   r   )r   loadsr    )r)   cookie_valuer   s      r*   user_from_cookiez!IdentityProvider.user_from_cookiej  sK    zz,'L M
 	
r,   c                    | j                   r| j                   S t        j                  dd|j                  j                         S )zReturn the login cookie name

        Uses IdentityProvider.cookie_name, if defined.
        Default is to generate a string taking host into account to avoid
        collisions for multiple servers on one hostname with different ports.
        -z	username-)rD   _non_alphanumsubrequesthostrj   s     r*   rw   z IdentityProvider.get_cookie_namev  s>     ### $$SIgoo6J6J5K*LMMr,   c                x   i }|j                  | j                         |j                  dd       | j                  }||j                  j
                  dk(  }|r|j                  dd       |j                  d|j                         | j                  |      } |j                  || j                  |      fi | y)z9Call this on handlers to set the login cookie for successhttponlyTNhttpssecurepath)
updatecookie_options
setdefaultrF   r   protocolbase_urlrw   set_secure_cookier   )r)   rk   r   r   rF   rD   s         r*   ru   z!IdentityProvider.set_login_cookie  s    d112!!*d3 ** #OO44?M%%h5!!&'*:*:;**73!!!+t/B/B4/H[N[r,   c                   t        j                  |      }t        j                  j                  t        j                  j
                        t        j                  d      z
  }t               }|j                  |dd       t        j                  |      |d<   ||d<   |r||d<   |j                  d	|j                                y
)a  Deletes the cookie with the given name.

        Tornado's cookie handling currently (Jan 2018) stores cookies in a dict
        keyed by name, so it can only modify one cookie with a given name per
        response. The browser can store multiple cookies with the same name
        but different domains and/or paths. This method lets us clear multiple
        cookies with the same name.

        Due to limitations of the cookie protocol, you must pass the same
        path and domain to clear a cookie as were used when that cookie
        was set (but there is no way to find out on the server side
        which values were used for a given cookie).
        )tzim  )daysr#   z""expiresr   domainz
Set-CookieN)r   
native_strdatetimenowtimezoneutc	timedeltar   setr   format_timestamp
add_headerOutputString)r)   rk   r   r   r   r   morsels          r*   _force_clear_cookiez$IdentityProvider._force_clear_cookie  s        &##''8+<+<+@+@'AHDVDV\_D`` &

4T"$55g>yv%F8<)<)<)>?r,   c                    i }|j                  | j                         |j                  d|j                        }| j	                  |      }|j                  ||       |r|dk7  r| j                  ||       yyy)z<Clear the login cookie, effectively logging out the session.r   )r   /N)r   r   r   r   rw   clear_cookier   )r)   rk   r   r   rD   s        r*   r{   z#IdentityProvider.clear_login_cookie  sx    d112((1A1AB**73[t4DCK
 $$Wk:  4r,   c                L    |j                   | j                  |      fi | j                  }|sy|j                         }	 | j	                  |      S # t
        $ rH}| j                  j                  d| d       | j                  j                  d|        Y d}~yd}~ww xY w)z[Get user from a cookie

        Calls user_from_cookie to deserialize cookie value
        Nz)Error unpacking user from cookie: cookie=T)exc_infoz"Error unpacking user from cookie: )	get_secure_cookierw   get_secure_cookie_kwargsrZ   r   	Exceptionry   debugerror)r)   rk   _user_cookieuser_cookiees        r*   rt   z IdentityProvider.get_user_cookie  s     1w00  )
++
 "))+	((55 	HHNNF{mT_cNdHHNN?sCD		s   A 	B#>BB#z(token|bearer)\s+(.+)c                    |j                  dd      }|sR| j                  j                  |j                  j                  j                  dd            }|r|j                  d      }|S )zGet the user token from a request

        Default:

        - in URL parameters: ?token=<token>
        - in header: Authorization: token <token>
        rG   r#   Authorization   )get_argumentauth_header_patmatchr   headersgetgroup)r)   rk   
user_tokenms       r*   	get_tokenzIdentityProvider.get_token  s]     ))'26
$$**7??+B+B+F+FXZ+[\AWWQZ
r,   c                  K   t        j                  d|j                        }|sy| j                  |      }d}||k(  r2| j                  j                  d|j                  j                         d}|rL| j                  |      }t        |t         j                        r
| d{   }|}|| j                  |      }|S y7 w)zIdentify the user based on a token in the URL or Authorization header

        Returns:
        - uuid if authenticated
        - None if not
        r$   NFz-Accepting token-authenticated request from %sT)ra   rq   rG   r   ry   r   r   	remote_iprt   r7   rs   r}   )r)   rk   rG   r   authenticated_userr   s          r*   rr   zIdentityProvider.get_user_token  s      |W]]3^^G,
HHNN?)) !M ((1E%-# %D|33G<K $s   B C"B?#Cc                    t        j                         j                  }t               }d| x}}d|d    }d}|j                  j                  d|        t        ||||d|      S )zGenerate a random anonymous user.

        For use when a single shared token is used,
        but does not identify a user.
        z
Anonymous Ar   Nz5Generating new user for token-authenticated request: )uuiduuid4hexr   ry   r   r    )r)   rk   user_idmoonr   r   r   r   s           r*   r}   z(IdentityProvider.generate_anonymous_user  ss     **,""%' *4&11|tAwi=QRYQZ[\GT<4GGr,   c                &    | j                  |       S )a3  Should the Handler check for CORS origin validation?

        Origin check should be skipped for token-authenticated requests.

        Returns:
        - True, if Handler must check for valid CORS origin.
        - False, if Handler should skip origin check since requests are token-authenticated.
        )is_token_authenticatedrj   s     r*   should_check_originz$IdentityProvider.should_check_origin  s     ..w777r,   c                4    |j                    t        |dd      S )zReturns True if handler has been token authenticated. Otherwise, False.

        Login with a token is used to signal certain things, such as:

        - permit access to REST API
        - xsrf protection
        - skip origin-checks for scripts
        rv   F)r   rp   rj   s     r*   r   z'IdentityProvider.is_token_authenticated   s     	w 6>>r,   c                   |j                   sNd}||j                  j                  | d       | j                  s|j                  j                  | d       yy| j                  s|j                  j                  d       yy)z~Check the application's security.

        Show messages, or abort if necessary, based on the security configuration.
        z<WARNING: The Jupyter server is listening on all IP addressesNz3 and not using encryption. This is not recommended.zK and not using authentication. This is highly insecure and not recommended.z`All authentication is disabled.  Anyone who can connect to this server will be able to run code.)ipry   rz   r|   )r)   appssl_optionsrz   s       r*   validate_securityz"IdentityProvider.validate_security-  s     vvTG"7)+^ _`$$i  C C %
 ""GGOOT #r,   c                    |j                  dd      }d}| j                  s,| j                  j                  d       | j	                  |      S | j
                  r4| j
                  |k(  r%t        j                  d| j                  |            S |S )_Process login form data

        Return authenticated User if successful, None if not.
        passwordr#   r   N6Accepting anonymous login because auth fully disabled!r    )	r   r|   ry   rz   r}   rG   ra   rq   user_for_token)r)   rk   typed_passwordr   s       r*   process_login_formz#IdentityProvider.process_login_formE  s~    
 !--j"-E  HHUV//88::$**666&$"5"5n"EFFr,   c                     y)zIs authentication enabled?

        Should always be True, but may be False in rare, insecure cases
        where requests with no auth are allowed.

        Previously: LoginHandler.get_login_available
        Tr5   r(   s    r*   r|   zIdentityProvider.auth_enabledU  s     r,   c                    | j                   S z\Whether a LoginHandler is needed - and therefore whether the login page should be displayed.r|   r(   s    r*   r   z IdentityProvider.login_available`          r,   c                     y)z"Whether a LogoutHandler is needed.Tr5   r(   s    r*   r   z!IdentityProvider.logout_availablee  s     r,   c                    |S )zUpdate cookie secret input

        Subclasses may call `h.update()` with any credentials that,
        when changed, should invalidate existing cookies, such as a
        password.

        The updated hashlib object should be returned.

        r5   r)   hs     r*   cookie_secret_hookz#IdentityProvider.cookie_secret_hookj  s	     r,   )rk   web.RequestHandlerreturnz&User | None | t.Awaitable[User | None]rk   r  r  User | None)rk   r  r   dict[UpdatableField, str]r  r    )r   r
  r  Noner   r    r   r
  r  r    rk   r  r  r  )r   r    r  zdict[str, t.Any])r  zlist[tuple[str, object]])r   r    r  r!   )r   r!   r  r	  )rk   r  r  r!   )rk   r  r   r    r  r  )r   N)
rk   r  r   r!   r   r!   r   r$   r  r  )rk   r  r  r$   )rk   r  r  r    rk   r  r  boolr&   r   t.Anyr   zdict[str, t.Any] | Noner  r  r  	hmac.HMACr  r  )@r0   r1   r2   r3   r   r   rD   r4   r   r   r
   rF   r   tagrG   r   r	   RequestHandlerr   r   r   r   r`   ra   rb   rc   r]   rR   r   r\   r   rg   rV   rl   ri   r   r   r   r   r   r   r   r   rw   ru   r   r{   rt   recompile
IGNORECASEr   r   rr   r}   r   r   r   r   propertyr|   r   r   r  r5   r,   r*   r@   r@   v   s     4;
_`4K0  A
N BFY
	BM>   $A
  .5
.  
cc! 
* $ B  <=	  @  56	 4


>234iJK	 OWD D   !	! "	! 15T
J-:
'+Z)6O	&""

(


N\" ]a@)@14@<?@OY@	@6;)	/. !bjj!92==IO !FH	8?  04 - 
	0    ! !  
r,   r@   c                      e Zd ZdZ edd ed            Z edd ed            Z edd ed            Z	 e
d	      d
        Z e
d      d        Zedd       Zedd       ZddZddZd ZddZ	 d	 	 	 	 	 d fdZddZ xZS )PasswordIdentityProviderzA password identity provider.r#   Ta  
            Hashed password to use for web authentication.

            To generate, type in a python/IPython shell:

                from jupyter_server.auth import passwd; passwd()

            The string should be of the form type:salt:hashed-password.
            rA   Fao  
            Forces users to use a password for the Jupyter server.
            This is useful in a multi user environment, for instance when
            everybody in the LAN can access each other's machine through ssh.

            In such a case, serving on localhost is not secure since
            any user can connect to the Jupyter server via ssh.

            a  
            Allow password to be changed at login for the Jupyter server.

            While logging in with a token, the Jupyter server UI will give the opportunity to
            the user to enter a new password at the same time that will replace
            the token login mechanism.

            This can be set to False to prevent changing password from the UI/API.
            rV   c                .    t        | j                         S r&   )r  hashed_passwordr(   s    r*   _need_token_defaultz,PasswordIdentityProvider._need_token_default  s    ,,---r,   r]   c                
    g dS )Nr   r5   r(   s    r*   _default_updatable_fieldsz2PasswordIdentityProvider._default_updatable_fields  s    
 	
r,   c                    | j                   S r   r   r(   s    r*   r   z(PasswordIdentityProvider.login_available  r   r,   c                H    t        | j                  xs | j                        S )z"Return whether any auth is enabled)r  r  rG   r(   s    r*   r|   z%PasswordIdentityProvider.auth_enabled  s     D((6DJJ77r,   c                R    | j                   D ]  }||v st        ||||           |S r   )r]   setattr)r)   r   r   r=   s       r*   r   z*PasswordIdentityProvider.update_user_model  s3    **E	!eYu-=> + r,   c                <    | j                  ||j                         y)z#Persist the user model to a cookie.N)ru   r   rj   s     r*   r   z+PasswordIdentityProvider.persist_user_model  s    gw';';<r,   c                .    t        | j                  |      S )z1Check password against our stored hashed password)r   r  )r)   r   s     r*   r   z%PasswordIdentityProvider.passwd_check  s    D00(;;r,   c                   |j                  dd      }|j                  dd      }d}| j                  s,| j                  j                  d       | j	                  |      S | j                  |      r|s| j	                  |      S | j                  r| j                  |k(  r| j	                  |      }|r| j                  r|j                  j                  dd      }t        j                  j                  |d      }t        ||	      | _        | j                  j                  t!        d
      j#                  |             |S )r   r   r#   r   new_passwordNr   
config_dirzjupyter_server_config.json)config_filezWrote hashed password to {file})file)r   r|   ry   rz   r}   r   rG   allow_password_changesettingsr   rP   r   joinr   r  infor   format)r)   rk   r   r(  r   r)  r*  s          r*   r   z+PasswordIdentityProvider.process_login_form  s   
 !--j"-E++NB+G  HHUV//88^,\//88ZZDJJ.8//8D : :$--11,C
 ggll:7ST'3Lk'Z$e$EFMMS^M_`r,   c                \   t         |   ||       | j                  r| j                  s| j                  j                  t        d             | j                  j                  t        d             | j                  j                  t        d             t        j                  d       yyy)zHandle security validation.>Jupyter servers are configured to only be run with a password.1Hint: run the following command to set a password)	$ python -m jupyter_server.auth passwordr   N)	superr   password_requiredr  ry   criticalr   sysexit)r)   r   r   	__class__s      r*   r   z*PasswordIdentityProvider.validate_security  s     	!#{3!!4+?+?HHVW HHe$WXYHHe$PQRHHQK ,@!r,   c                X    |j                  | j                  j                                |S )zpInclude password in cookie secret.

        This makes it so changing the password invalidates cookies.
        )r   r  encoder  s     r*   r  z+PasswordIdentityProvider.cookie_secret_hook  s$    
 	
%%,,./r,   r  r  r  r  r  r&   r  r  )r0   r1   r2   r3   r   r   r  r
   r6  r,  r   r  r   r  r   r|   r   r   r   r   r   r  __classcell__)r:  s   @r*   r  r  w  s    '


O  

  !

  \. .  
 !
 ! ! 8 8=<6 04 - 
	r,   r  c                      e Zd ZdZ e       Z ed      d        Z ed      d        Ze	d        Z
ddZe	dd       Zdd	Zdd
Z	 d	 	 	 	 	 ddZy)LegacyIdentityProviderzLegacy IdentityProvider for use with custom LoginHandlers

    Login configuration has moved from LoginHandler to IdentityProvider
    in Jupyter Server 2.0.
    r-  c                4    | j                   | j                  dS )N)rG   r   )rG   r  r(   s    r*   _default_settingsz(LegacyIdentityProvider._default_settings  s     ZZ,,
 	
r,   r   c                    ddl m} |S )Nr   )LegacyLoginHandler)loginrD  )r)   rD  s     r*   _default_login_handler_classz3LegacyIdentityProvider._default_login_handler_class  s    -!!r,   c                    | j                   S r&   )r   r(   s    r*   r|   z#LegacyIdentityProvider.auth_enabled  s    ###r,   c                T    | j                   j                  |      }|yt        |      S )rn   N)r   rl   r>   )r)   rk   r   s      r*   rl   zLegacyIdentityProvider.get_user  s+    ''009<$T**r,   c                ^    t        | j                  j                  | j                              S r&   )r  r   get_login_availabler-  r(   s    r*   r   z&LegacyIdentityProvider.login_available#  s*    $$88
 	
r,   c                J    t        | j                  j                  |            S )zWhether we should check origin.)r  r   r   rj   s     r*   r   z*LegacyIdentityProvider.should_check_origin+  s    D,,@@IJJr,   c                J    t        | j                  j                  |            S )z#Whether we are token authenticated.)r  r   r   rj   s     r*   r   z-LegacyIdentityProvider.is_token_authenticated/  s    D,,CCGLMMr,   Nc                n   | j                   r| j                  s| j                  j                  t	        d             | j                  j                  t	        d             | j                  j                  t	        d             t        j                  d       | j                  j                  ||       y)zValidate security.r2  r3  r4  r   N)	r6  r  ry   r7  r   r8  r9  r   r   )r)   r   r   s      r*   r   z(LegacyIdentityProvider.validate_security3  s     !!4+?+?HHVW HHe$WXYHHe$PQRHHQK  22	
r,   r  r=  r  r&   r  )r0   r1   r2   r3   r   r-  r   rB  rF  r  r|   rl   r   r   r   r   r5   r,   r*   r@  r@    s     vHZ
 
 "#" $"
 $ $+ 
 
KN 04

 -
 
	
r,   r@  )r;   r  r  r    )3r3   
__future__r   rW   r   hmacr   rP   r  r8  typingra   r   dataclassesr   r   http.cookiesr   tornador   r   r	   	traitletsr
   r   r   r   r   r   r   r   r   traitlets.configr   jupyter_server.transutilsr   securityr   r   utilsr   TYPE_CHECKINGr  r   Literalrc   r    r>   r@   r  r@  r5   r,   r*   <module>r[     s    #     	 	 
   )  ) ) Z Z Z 0 + 0 )??

?+ TU +* +* +*\:~* ~BG/ GTA
5 A
r,   