
    k7i                    f    S r SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  \
" \5      r " S S\5      rg)	zEnhanced authentication middleware with better error messages.

This module provides enhanced versions of MCP SDK authentication middleware
that return more helpful error messages for developers troubleshooting
authentication issues.
    )annotationsN)RequireAuthMiddleware)Send)
get_loggerc                  6    \ rS rSrSr          SS jrSrg)r      zEnhanced authentication middleware with detailed error messages.

Extends the SDK's RequireAuthMiddleware to provide more actionable
error messages when authentication fails. This helps developers
understand what went wrong and how to fix it.
c                  #    UnUS:X  a	  US:X  a  SnOUS:X  a   SU S3SU S3/nU R                   (       a  UR                  SU R                    S35        S	S
R                  U5       3nX5S.n[        R                  " U5      R                  5       n	U" SUSS[        [        U	5      5      R                  5       4SUR                  5       4/S.5      I Sh  vN   U" SU	S.5      I Sh  vN   [        R                  SUU5        g N/ N7f)af  Send an authentication error response with enhanced error messages.

Overrides the SDK's _send_auth_error to provide more detailed
error descriptions that help developers troubleshoot authentication
issues.

Args:
    send: ASGI send callable
    status_code: HTTP status code (401 or 403)
    error: OAuth error code
    description: Base error description
invalid_tokeni  zAuthentication failed. The provided bearer token is invalid, expired, or no longer recognized by the server. To resolve: clear authentication tokens in your MCP client and reconnect. Your client should automatically re-register and obtain new tokens.insufficient_scopezerror=""zerror_description="zresource_metadata="zBearer z, )errorerror_descriptionzhttp.response.start)s   content-types   application/jsons   content-lengths   www-authenticate)typestatusheadersNzhttp.response.body)r   bodyz#Auth error returned: %s (status=%d))
resource_metadata_urlappendjoinjsondumpsencodestrlenloggerinfo)
selfsendstatus_coder   descriptionenhanced_descriptionwww_auth_partswww_authenticater   
body_bytess
             X/home/james-whalen/.local/lib/python3.13/site-packages/fastmcp/server/auth/middleware.py_send_auth_error&RequireAuthMiddleware._send_auth_error   sL       +O#s(:V !
 ** eWA!"6!7q9
 %%!!$78R8R7SST"UV$TYY~%>$?@ JZZ%,,.
-%:&C
O(<(C(C(EF(*:*A*A*CD

 
	
 
	
 ,"
 	
 	
 	1	
'
	
	
s$   CDDD*D	+D	D N)
r   r   r   intr   r   r    r   returnNone)__name__
__module____qualname____firstlineno____doc__r&   __static_attributes__r(       r%   r   r      s:    B
B
'*B
36B
EHB
	B
r2   r   )r0   
__future__r   r   &mcp.server.auth.middleware.bearer_authr   SDKRequireAuthMiddlewarestarlette.typesr   fastmcp.utilities.loggingr   r,   r   r(   r2   r%   <module>r8      s8    #  ! 0	H	J
4 J
r2   