
    GjA                         S r SSKrSSKJrJrJr  SSKJrJr  S\	\-  \-  S\	4S jr
S\	S	\	S\4S
 jrS\\	-  S-  S\S-  4S jrg)zKUtilities for OAuth 2.0 Resource Indicators (RFC 8707) and PKCE (RFC 7636).    N)urlparseurlsplit
urlunsplit)AnyUrlHttpUrlurlreturnc                     [        U 5      n[        U5      n[        UR                  UR                  R                  5       UR                  R                  5       SS95      nU$ )a(  Convert server URL to canonical resource URL per RFC 8707.

RFC 8707 section 2 states that resource URIs "MUST NOT include a fragment component".
Returns absolute URI with lowercase scheme/host for canonical form.

Args:
    url: Server URL to convert

Returns:
    Canonical resource URL string
 )schemenetlocfragment)strr   r   _replacer   lowerr   )r   url_strparsed	canonicals       W/Users/admin/workspace/tools/venv/lib/python3.13/site-packages/mcp/shared/auth_utils.pyresource_url_from_server_urlr   	   sV     #hG gF6??&--2E2E2GPVP]P]PcPcPepr?stI    requested_resourceconfigured_resourcec                    [        U 5      n[        U5      nUR                  R                  5       UR                  R                  5       :w  d6  UR                  R                  5       UR                  R                  5       :w  a  gUR                  nUR                  nUR                  S5      (       d  US-  nUR                  S5      (       d  US-  nUR                  U5      $ )a  Check if a requested resource URL matches a configured resource URL.

A requested resource matches if it has the same scheme, domain, port,
and its path starts with the configured resource's path. This allows
hierarchical matching where a token for a parent resource can be used
for child resources.

Args:
    requested_resource: The resource URL being requested
    configured_resource: The resource URL that has been configured

Returns:
    True if the requested resource matches the configured resource
F/)r   r   r   r   pathendswith
startswith)r   r   	requested
configuredrequested_pathconfigured_paths         r   check_resource_allowedr#      s      +,I-.J :#4#4#:#:#<<	@P@P@V@V@X\f\m\m\s\s\u@u ^^N ooO""3''###C((3 $$_55r   
expires_inc                 L    U c  g[         R                   " 5       [        U 5      -   $ )zCalculate token expiry timestamp from expires_in seconds.

Args:
    expires_in: Seconds until token expiration (may be string from some servers)

Returns:
    Unix timestamp when token expires, or None if no expiry specified
N)timeint)r$   s    r   calculate_token_expiryr(   D   s"     99;Z((r   )__doc__r&   urllib.parser   r   r   pydanticr   r   r   r   boolr#   r'   floatr(    r   r   <module>r/      sl    Q  7 7 $cGmf&<  ,"6s "6 "6QU "6J)sSy4'7 )EDL )r   