o
    i)                     @  sh   d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ eeZG dd	 d	eZdS )
aU  Debug token verifier for testing and special cases.

This module provides a flexible token verifier that delegates validation
to a custom callable. Useful for testing, development, or scenarios where
standard verification isn't possible (like opaque tokens without introspection).

Example:
    ```python
    from fastmcp import FastMCP
    from fastmcp.server.auth.providers.debug import DebugTokenVerifier

    # Accept all tokens (default - useful for testing)
    auth = DebugTokenVerifier()

    # Custom sync validation logic
    auth = DebugTokenVerifier(validate=lambda token: token.startswith("valid-"))

    # Custom async validation logic
    async def check_cache(token: str) -> bool:
        return await redis.exists(f"token:{token}")

    auth = DebugTokenVerifier(validate=check_cache)

    mcp = FastMCP("My Server", auth=auth)
    ```
    )annotationsN)	AwaitableCallable)TokenVerifier)AccessToken)
get_loggerc                      s:   e Zd ZdZdd dddfd fddZdddZ  ZS )DebugTokenVerifiera   Token verifier with custom validation logic.

    This verifier delegates token validation to a user-provided callable.
    By default, it accepts all non-empty tokens (useful for testing).

    Use cases:
    - Testing: Accept any token without real verification
    - Development: Custom validation logic for prototyping
    - Opaque tokens: When you have tokens with no introspection endpoint

    WARNING: This bypasses standard security checks. Only use in controlled
    environments or when you understand the security implications.
    c                 C  s   dS )NT )tokenr	   r	   i/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/server/auth/providers/debug.py<lambda>:   s    zDebugTokenVerifier.<lambda>zdebug-clientNvalidate8Callable[[str], bool] | Callable[[str], Awaitable[bool]]	client_idstrscopeslist[str] | Nonerequired_scopesc                   s(   t  j|d || _|| _|pg | _dS )a  Initialize the debug token verifier.

        Args:
            validate: Callable that takes a token string and returns True if valid.
                Can be sync or async. Default accepts all tokens.
            client_id: Client ID to assign to validated tokens
            scopes: Scopes to assign to validated tokens
            required_scopes: Required scopes (inherited from TokenVerifier base class)
        )r   N)super__init__r   r   r   )selfr   r   r   r   	__class__r	   r   r   7   s   zDebugTokenVerifier.__init__r
   returnAccessToken | Nonec              
     s   |r|  std dS z*| |}t|r|I dH }n|}|s+td W dS t|| j| jdd|idW S  t	yS } ztjd|dd W Y d}~dS d}~ww )	zVerify token using custom validation logic.

        Args:
            token: The token string to validate

        Returns:
            AccessToken if validation succeeds, None otherwise
        zRejecting empty tokenNz0Token validation failed: callable returned Falser
   )r
   r   r   
expires_atclaimszToken validation error: %sT)exc_info)
striploggerdebugr   inspectisawaitabler   r   r   	Exception)r   r
   resultis_valider	   r	   r   verify_tokenM   s0   




zDebugTokenVerifier.verify_token)r   r   r   r   r   r   r   r   )r
   r   r   r   )__name__
__module____qualname____doc__r   r'   __classcell__r	   r	   r   r   r   (   s    r   )r+   
__future__r   r!   collections.abcr   r   fastmcp.server.authr   fastmcp.server.auth.authr   fastmcp.utilities.loggingr   r(   r   r   r	   r	   r	   r   <module>   s    