
    .h                         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	  e j
        edz           dd          Zde	dz  fdZ G d	 d
          ZdS )    N)ASGIAppReceiveScopeSend)AuthenticatedUser)AccessTokenauth_context)defaultreturnc                  J    t                                           } | r| j        ndS )z
    Get the access token from the current context.

    Returns:
        The access token if an authenticated user is available, None otherwise.
    N)auth_context_vargetaccess_token)	auth_users    d/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/mcp/server/auth/middleware/auth_context.pyget_access_tokenr      s(     !$$&&I%.89!!D8    c                   2    e Zd ZdZdefdZdededefdZ	dS )	AuthContextMiddlewareaZ  
    Middleware that extracts the authenticated user from the request
    and sets it in a contextvar for easy access throughout the request lifecycle.

    This middleware should be added after the AuthenticationMiddleware in the
    middleware stack to ensure that the user is properly authenticated before
    being stored in the context.
    appc                     || _         d S )N)r   )selfr   s     r   __init__zAuthContextMiddleware.__init__$   s    r   scopereceivesendc                 ~  K   |                     d          }t          |t                    rst                              |          }	 |                     |||           d {V  t                              |           d S # t                              |           w xY w|                     |||           d {V  d S )Nuser)r   
isinstancer   r   setr   reset)r   r   r   r   r   tokens         r   __call__zAuthContextMiddleware.__call__'   s      yy  d-.. 		1$((..E.hhugt444444444 &&u----- &&u---- ((5'400000000000s   B BN)
__name__
__module____qualname____doc__r   r   r   r   r   r#    r   r   r   r      sb         G    1E 1G 14 1 1 1 1 1 1r   r   )contextvarsstarlette.typesr   r   r   r   &mcp.server.auth.middleware.bearer_authr   mcp.server.auth.providerr   
ContextVarr   r   r   r(   r   r   <module>r.      s        9 9 9 9 9 9 9 9 9 9 9 9 D D D D D D 0 0 0 0 0 0 D;)*;d*BCD   
9+, 9 9 9 91 1 1 1 1 1 1 1 1 1r   