
    "<i                         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e          Z G 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                   L   e Zd ZU dZ eded          ZdZedz  e	d<   dZ
edz  e	d<   dZedz  e	d<   dZedz  e	d	<   dZedz  e	d
<   dZedz  e	d<   dZedz  e	d<   dZee         dz  e	d<   dZee         dz  e	d<   dZedz  e	d<    edd          e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                      t          |          S )Nr   )clsvs     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/server/auth/providers/auth0.py_parse_scopesz#Auth0ProviderSettings._parse_scopes9   s     A    )__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   %   sI        ++%%/  L %)J
T!((( IsTz   &*M9t#***HcDj"&Hj4&&&$(J
T!((( $M3:$$$(,OT#Y%,,,59 $s)d"2999"&OS4Z&&&_&X666  [ 76  r(   r   c                        e Zd ZdZeeeeeeeeededddeez  ez  deez  deez  deez  d	eez  ez  d
eez  ez  dee         ez  deez  dee         ez  de	dz  dee
z  ez  deddf fdZ x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   r5   r    r6   returnc                   t                               d |||||||||	|d
                                D                       }|j        st	          d          |j        st	          d          |j        st	          d          |j        st	          d          |j        st	          d          |j	        pdg}t                                          |j        |j        |j                                        |j        |j        |j        |j        ||j        |
|j        |	           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                 ,    i | ]\  }}|t           u||S r2   )r   ).0kr%   s      r&   
<dictcomp>z*Auth0Provider.__init__.<locals>.<dictcomp>   s3       Aq F?? 1 #??r(   )
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   r5   r    r6   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   r5   r    r6   settingsauth0_required_scopes	__class__s                  r&   rB   zAuth0Provider.__init__W   s   R )77  #-!*%2 ( (",'6%24P'6  %''  
 
& " 	d   ! 	b   % 	j     	`     	`   !) 8 FXJ*("0AACC&&*"01)1)N)$4*G 	 	
 	
 	
 	L!	
 	
 	
 	
 	
r(   )r)   r*   r+   r,   r   r   r/   r   r0   r   bytesboolrB   __classcell__)rI   s   @r&   r4   r4   ?   s`        4 28#)'-"(/517/5'-<B/317.2j
 j
 j
 $w.j
 =	j

 W}j
 -j
 s"W,j
 $w.j
 cW,j
 W}j
 '+3i'&9j
 &,j
 uw.j
 (,j
 
j
 j
 j
 j
 j
 j
 j
 j
 j
 j
r(   r4   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)   rD   r   r4   r2   r(   r&   <module>rU      s0   . 2 1 1 1 1 1 ; ; ; ; ; ; ; ; ; ; > > > > > > > > 4 4 4 4 4 4 % % % % % % / / / / / / 0 0 0 0 0 0 3 3 3 3 3 3 3 3	H		    L   4B
 B
 B
 B
 B
I B
 B
 B
 B
 B
r(   