U
    öÕ/e*  ã                   @  s8   d Z ddlmZ ddlZe e¡ZdZG dd„ dƒZdS )zI Provide a mixin class to add authorization hooks to a request handler.

é    )ÚannotationsN)Ú	AuthMixinc                   @  s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   zÿ This mixin adds the expected Tornado authorization hooks:

    * get_login_url
    * get_current_user
    * prepare

    All of these delegate to the a :class:`~bokeh.serve.auth_provider.AuthProvider`
    confiured on the Bokeh tornado application.

    c                 C  s@   | j jjdk	r| j j | ¡S | j jjdk	r4| j jjS tdƒ‚dS )zm Delegates to``get_login_url`` method of the auth provider, or the
        ``login_url`` attribute.

        NzSlogin_url or get_login_url() must be supplied when authentication hooks are enabled)ÚapplicationÚauth_providerÚget_login_urlZ	login_urlÚRuntimeError©Úself© r
   úA/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/server/views/auth_mixin.pyr   3   s
    
zAuthMixin.get_login_urlc                 C  s    | j jjdk	r| j j | ¡S dS )zW Delegate to the synchronous ``get_user`` method of the auth
        provider

        NZdefault_user)r   r   Zget_userr   r
   r
   r   Úget_current_user>   s    zAuthMixin.get_current_userc                 Ã  s(   | j jjdk	r$| j j | ¡I dH | _dS )z4 Async counterpart to ``get_current_user``

        N)r   r   Zget_user_asyncZcurrent_userr   r
   r
   r   ÚprepareG   s    zAuthMixin.prepareN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r
   r
   r
   r   r   '   s   	r   )	r   Ú
__future__r   ÚloggingÚ	getLoggerr   ÚlogÚ__all__r   r
   r
   r
   r   Ú<module>   s
   

