a
    ^g                     @  sr   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZmZmZ G dd dZdS )	    )annotationsN)AuthCredentialsAuthenticationBackendAuthenticationErrorUnauthenticatedUser)HTTPConnection)PlainTextResponseResponse)ASGIAppReceiveScopeSendc                   @  sL   e Zd ZddddddddZd	d
dddddZeddddddZdS )AuthenticationMiddlewareNr
   r   zGtyping.Callable[[HTTPConnection, AuthenticationError], Response] | NoneNone)appbackendon_errorreturnc                 C  s$   || _ || _|d ur|n| j| _d S )N)r   r   default_on_errorr   )selfr   r   r    r   q/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/starlette/middleware/authentication.py__init__   s    z!AuthenticationMiddleware.__init__r   r   r   )scopereceivesendr   c              
     s   |d dvr$|  |||I d H  d S t|}z| j|I d H }W nf ty } zN| ||}|d dkr|dddI d H  n||||I d H  W Y d }~d S d }~0 0 |d u rt t f}|\|d< |d< |  |||I d H  d S )	Ntype)http	websocketr   zwebsocket.closei  )r   codeauthuser)r   r   r   Zauthenticater   r   r   r   )r   r   r   r   connZauth_resultexcresponser   r   r   __call__   s     z!AuthenticationMiddleware.__call__r   	Exceptionr	   )r"   r#   r   c                 C  s   t t|ddS )Ni  )status_code)r   str)r"   r#   r   r   r   r   2   s    z)AuthenticationMiddleware.default_on_error)N)__name__
__module____qualname__r   r%   staticmethodr   r   r   r   r   r      s
    r   )
__future__r   typingZstarlette.authenticationr   r   r   r   Zstarlette.requestsr   Zstarlette.responsesr   r	   Zstarlette.typesr
   r   r   r   r   r   r   r   r   <module>   s   