
    kKj                       d Z ddlm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 ddlmZ  ej                  e      ZerddlmZ dd	lmZ dd
lmZ e	 G d d             Zeegef   eegee   f   z  ZddZddZ	 	 	 	 	 	 ddZy)a  Authorization checks for FastMCP components.

Auth checks are callables that receive an ``AuthContext`` and return True to
allow access or False to deny it. They can also raise ``AuthorizationError`` to
deny with a custom message; other exceptions are masked and treated as denial.
    )annotationsN)	AwaitableCallable)	dataclass)TYPE_CHECKINGcast)AuthorizationError)AccessTokenTool)FastMCPComponentc                  8    e Zd ZU dZded<   ded<   edd       Zy)	AuthContexta   Context passed to auth check callables.

    Attributes:
        token: The current access token, or None if unauthenticated.
        component: The tool, resource, resource template, or prompt being accessed.
        tool: Backwards-compatible alias for component when it is a Tool.
    zAccessToken | Nonetokenr   	componentc                V    ddl m} t        | j                  |      r| j                  S dS )z7Backwards-compatible access to the component as a Tool.r   r   N)fastmcp.tools.baser   
isinstancer   )selfr   s     p/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/utilities/authorization.pytoolzAuthContext.tool'   s#     	,!+DNND!At~~KtK    N)returnzTool | None)__name__
__module____qualname____doc____annotations__propertyr    r   r   r   r      s)     L Lr   r   c                 *    t        |       dfd}|S )z&Require all of the given OAuth scopes.c                z    | j                   yj                  t        | j                   j                              S )NF)r   issubsetsetscopes)ctxrequireds    r   checkzrequire_scopes.<locals>.check6   s0    99  SYY%5%5!677r   r&   r   r   boolr$   )r%   r(   r'   s     @r   require_scopesr,   2   s    6{H8
 Lr   c               .     t        |      d fd}|S )z>Require scopes when the accessed component has a specific tag.c                    | j                   j                  vry| j                  yj                  t	        | j                  j
                              S )NTF)r   tagsr   r#   r$   r%   )r&   r'   tags    r   r(   zrestrict_tag.<locals>.checkB   sE    cmm(((99  SYY%5%5!677r   r)   r+   )r0   r%   r(   r'   s   `  @r   restrict_tagr1   >   s    6{H8 Lr   c                ^  K   t        | t              s| gn| }t        t        t           |      }|D ].  }	  ||      }t	        j
                  |      r
| d{   }|s y0 y7 # t        $ r  t        $ r3 t        j                  dt        |dt        |             dd       Y  yw xY ww)zRun auth checks with AND logic.NFzAuth check r   z raised an unexpected exceptionT)exc_info)r   listr   	AuthCheckinspectisawaitabler	   	Exceptionloggerwarninggetattrrepr)checksr&   
check_listr(   results        r   run_auth_checksr@   L   s     
 ",FD!9&vJd9oz2J	3ZF""6*%  "  & " 	 	NNgeZeEF G1 1  
 	s;   2B-"A%A#A%B-#A%%AB*&B-)B**B-)r%   strr   r5   )r0   rA   r%   z	list[str]r   r5   )r=   zAuthCheck | list[AuthCheck]r&   r   r   r*   )r   
__future__r   r6   loggingcollections.abcr   r   dataclassesr   typingr   r   fastmcp.exceptionsr	   	getLoggerr   r9   fastmcp.server.authr
   r   r   fastmcp.utilities.componentsr   r   r*   r5   r,   r1   r@   r    r   r   <module>rK      s    #   / ! & 1			8	$/'= L L L( k]D()Hk]IdO5S,TT		'	 
r   