o
    i                     @   s   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZ eeZG d
d deZG dd deZdS )a  Auth0 OAuth provider for FastMCP.

This module provides a complete Auth0 integration that's ready to use with
just the configuration URL, client ID, client secret, audience, and base URL.

Example:
    ```python
    from fastmcp import FastMCP
    from fastmcp.server.auth.providers.auth0 import Auth0Provider

    # Simple Auth0 OAuth protection
    auth = Auth0Provider(
        config_url="https://auth0.config.url",
        client_id="your-auth0-client-id",
        client_secret="your-auth0-client-secret",
        audience="your-auth0-api-audience",
        base_url="http://localhost:8000",
    )

    mcp = FastMCP("My Protected Server", auth=auth)
    ```
    )AsyncKeyValue)
AnyHttpUrl	SecretStrfield_validator)BaseSettingsSettingsConfigDict)	OIDCProxy)ENV_FILEparse_scopes)
get_logger)NotSetNotSetTc                   @   s   e Zd ZU dZededdZdZedB e	d< dZ
edB e	d< dZedB e	d< dZedB e	d	< dZedB e	d
< dZedB e	d< dZedB e	d< dZee dB e	d< dZee dB e	d< dZedB e	d< edddedd ZdS )Auth0ProviderSettingsz!Settings for Auth0 OIDC provider.FASTMCP_SERVER_AUTH_AUTH0_ignore)
env_prefixenv_fileextraN
config_url	client_idclient_secretaudiencebase_url
issuer_urlredirect_pathrequired_scopesallowed_client_redirect_urisjwt_signing_keybefore)modec                 C   s   t |S )Nr
   )clsv r#   i/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/server/auth/providers/auth0.py_parse_scopes9   s   z#Auth0ProviderSettings._parse_scopes)__name__
__module____qualname____doc__r   r	   model_configr   r   __annotations__r   strr   r   r   r   r   r   r   listr   r   r   classmethodr%   r#   r#   r#   r$   r   %   s(   
 
r   c                       s   e Zd ZdZeeeeeeeeededddeeB eB deeB deeB deeB d	eeB eB d
eeB eB dee eB deeB dee eB de	dB dee
B eB deddf fddZ  ZS )Auth0Providera  An Auth0 provider implementation for FastMCP.

    This provider is a complete Auth0 integration that's ready to use with
    just the configuration URL, client ID, client secret, audience, and base URL.

    Example:
        ```python
        from fastmcp import FastMCP
        from fastmcp.server.auth.providers.auth0 import Auth0Provider

        # Simple Auth0 OAuth protection
        auth = Auth0Provider(
            config_url="https://auth0.config.url",
            client_id="your-auth0-client-id",
            client_secret="your-auth0-client-secret",
            audience="your-auth0-api-audience",
            base_url="http://localhost:8000",
        )

        mcp = FastMCP("My Protected Server", auth=auth)
        ```
    NT)r   r   r   r   r   r   r   r   r   client_storager   require_authorization_consentr   r   r   r   r   r   r   r   r   r0   r   r1   returnc                   s   t dd |||||||||	|d
 D }|jstd|js%td|js,td|js3td|js:td|j	p?d	g}t
 j|j|j|j |j|j|j|j||j|
|j|d
 td|j| dS )aV  Initialize Auth0 OAuth provider.

        Args:
            config_url: Auth0 config URL
            client_id: Auth0 application client id
            client_secret: Auth0 application client secret
            audience: Auth0 API audience
            base_url: Public URL where OAuth endpoints will be accessible (includes any mount path)
            issuer_url: Issuer URL for OAuth metadata (defaults to base_url). Use root-level URL
                to avoid 404s during discovery when mounting under a path.
            required_scopes: Required Auth0 scopes (defaults to ["openid"])
            redirect_path: Redirect path configured in Auth0 application
            allowed_client_redirect_uris: List of allowed redirect URI patterns for MCP clients.
                If None (default), all URIs are allowed. If empty list, no URIs are allowed.
            client_storage: Storage backend for OAuth state (client registrations, encrypted tokens).
                If None, a DiskStore will be created in the data directory (derived from `platformdirs`). The
                disk store will be encrypted using a key derived from the JWT Signing Key.
            jwt_signing_key: Secret for signing FastMCP JWT tokens (any string or bytes). If bytes are provided,
                they will be used as is. If a string is provided, it will be derived into a 32-byte key. If not
                provided, the upstream client secret will be used to derive a 32-byte key using PBKDF2.
            require_authorization_consent: Whether to require user consent before authorizing clients (default True).
                When True, users see a consent screen before being redirected to Auth0.
                When False, authorization proceeds directly without user confirmation.
                SECURITY WARNING: Only disable for local development or testing environments.
        c                 S   s   i | ]\}}|t ur||qS r#   )r   ).0kr"   r#   r#   r$   
<dictcomp>   s
    z*Auth0Provider.__init__.<locals>.<dictcomp>)
r   r   r   r   r   r   r   r   r   r   zRconfig_url is required - set via parameter or FASTMCP_SERVER_AUTH_AUTH0_CONFIG_URLzPclient_id is required - set via parameter or FASTMCP_SERVER_AUTH_AUTH0_CLIENT_IDzXclient_secret is required - set via parameter or FASTMCP_SERVER_AUTH_AUTH0_CLIENT_SECRETzNaudience is required - set via parameter or FASTMCP_SERVER_AUTH_AUTH0_AUDIENCEzNbase_url is required - set via parameter or FASTMCP_SERVER_AUTH_AUTH0_BASE_URLopenid)r   r   r   r   r   r   r   r   r   r0   r   r1   z>Initialized Auth0 OAuth provider for client %s with scopes: %sN)r   model_validateitemsr   
ValueErrorr   r   r   r   r   super__init__get_secret_valuer   r   r   r   loggerdebug)selfr   r   r   r   r   r   r   r   r   r0   r   r1   settingsauth0_required_scopes	__class__r#   r$   r;   W   sp   )zAuth0Provider.__init__)r&   r'   r(   r)   r   r   r,   r   r-   r   bytesboolr;   __classcell__r#   r#   rB   r$   r/   ?   sR    



	


r/   N)r)   key_value.aio.protocolsr   pydanticr   r   r   pydantic_settingsr   r   fastmcp.server.auth.oidc_proxyr   fastmcp.settingsr	   fastmcp.utilities.authr   fastmcp.utilities.loggingr   fastmcp.utilities.typesr   r   r&   r=   r   r/   r#   r#   r#   r$   <module>   s    