
    "<i)                        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	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                  8     e Zd ZdZd dddfd fdZddZ x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                    dS )NT )tokens    /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/server/auth/providers/debug.py<lambda>zDebugTokenVerifier.<lambda>:   s    4     zdebug-clientNvalidate8Callable[[str], bool] | Callable[[str], Awaitable[bool]]	client_idstrscopeslist[str] | Nonerequired_scopesc                z    t                                          |           || _        || _        |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__s        r   r   zDebugTokenVerifier.__init__7   s=    " 	999 "lr   r   returnAccessToken | Nonec                  K   |r|                                 st                              d           dS 	 |                     |          }t	          j        |          r	| d{V }n|}|st                              d           dS t          || j        | j        dd|i          S # t          $ r(}t                              d|d           Y d}~dS d}~ww xY 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es        r   verify_tokenzDebugTokenVerifier.verify_tokenM   s       	EKKMM 	LL01114	]]5))F"6** "!'<<<<<<! OPPPt .{'     	 	 	LL5q4LHHH44444	s   AB( B( (
C2CC)r   r   r   r   r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   r,   __classcell__)r   s   @r   r
   r
   (   sr         " .@-?'#',0# # # # # # #,% % % % % % % %r   r
   )r0   
__future__r   r&   collections.abcr   r   fastmcp.server.authr   fastmcp.server.auth.authr   fastmcp.utilities.loggingr   r-   r$   r
   r   r   r   <module>r7      s    6 # " " " " "  / / / / / / / / - - - - - - 0 0 0 0 0 0 0 0 0 0 0 0	H		J J J J J J J J J Jr   