
    kKj
                    z    d Z ddlmZ ddlm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y
)z-Keycloak authentication provider for FastMCP.    )annotations)
AnyHttpUrl)RemoteAuthProviderTokenVerifier)JWTVerifier)parse_scopes)
get_loggerc                  @     e Zd ZdZdddd	 	 	 	 	 	 	 	 	 d fdZ xZS )KeycloakAuthProvideraf  Keycloak authentication provider using Dynamic Client Registration (DCR).

    Requires Keycloak 26.6.0 or later, which includes the fix for DCR compatibility
    with MCP clients (https://github.com/keycloak/keycloak/pull/45309).

    Example:
        ```python
        from fastmcp import FastMCP
        from fastmcp.server.auth.providers.keycloak import KeycloakAuthProvider

        auth = KeycloakAuthProvider(
            realm_url="https://keycloak.example.com/realms/myrealm",
            base_url="https://my-mcp-server.example.com",
        )

        mcp = FastMCP("My App", auth=auth)
        ```
    N)required_scopesaudiencetoken_verifierc          	     D   t        |      j                  d      | _        |t        |      ndg}|'t	        | j                   d| j                  d||      }t
        |   |t        | j                        gt        t        |      j                  d                   y)a  Initialize the Keycloak auth provider.

        Args:
            realm_url: Keycloak realm URL (e.g., "https://keycloak.example.com/realms/myrealm")
            base_url: Public URL of this FastMCP server
            required_scopes: Scopes to require on incoming tokens. Defaults to
                ["openid"], which ensures the `sub` claim (user identifier) is
                present in the access token. Override to require additional scopes.
            audience: Optional audience(s) for JWT validation. Recommended for production.
            token_verifier: Optional custom token verifier. Defaults to a JWTVerifier
                configured for Keycloak's JWKS endpoint and issuer.
        /Nopenidz/protocol/openid-connect/certsRS256)jwks_uriissuer	algorithmr   r   )r   authorization_serversbase_url)strrstrip	realm_urlr   r   super__init__r   )selfr   r   r   r   r   parsed_scopes	__class__s          w/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/server/auth/providers/keycloak.pyr   zKeycloakAuthProvider.__init__#   s    * Y..s3-<-HL)xj 	 !( NN++IJ~~! -!N 	)#-dnn#=">H 4 4S 9: 	 	
    )
r   AnyHttpUrl | strr   r"   r   zlist[str] | str | Noner   zstr | list[str] | Noner   zTokenVerifier | None)__name__
__module____qualname____doc__r   __classcell__)r   s   @r    r   r      sO    0 37+//3'
 $'
 #	'

 0'
 )'
 -'
 '
r!   r   N)r&   
__future__r   pydanticr   fastmcp.server.authr   r   !fastmcp.server.auth.providers.jwtr   fastmcp.utilities.authr   fastmcp.utilities.loggingr	   r#   loggerr    r!   r    <module>r0      s1    3 "  A 9 / 0	H	;
- ;
r!   