+
    „WÝjã  ã                  ó<  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIHtHtH	t	H
t
 ^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHt ^ RIHtHt ^ R	IHtHtHt ]P<                  ! ]4      t ]!! 4       t"R
]#R&   ]PH                  ! 4       t%R R lt&R R lt'R R lt(R R lt)R R lt*R# )a~  Route-agnostic non-interactive (bearer-token) auth seam for the dashboard.

Any machine-credential provider plugs in here. A route opts in by registering its exact path via
:func:`register_token_route`; only registered paths are token-authable, so the auth surface of
existing routes never widens. :func:`token_auth_middleware` runs OUTERMOST (installed last) and
owns the decision for a token route: a recognised token attaches ``request.state.token_principal``
+ ``token_authenticated`` (the cookie gates honour that flag and never bounce to /login);
otherwise 401, or 503 when a provider's backing store was unreachable. Fails closed.
)ÚannotationsN)Ú	AwaitableÚCallableÚOptionalÚTuple)ÚRequest)ÚJSONResponseÚResponse)Úlist_token_providers)Ú
AuditEventÚ	audit_log)ÚProviderErrorÚTokenPrincipal)Ú	client_ipÚextract_bearerÚunreachable_responsezset[str]Ú_token_routesc               ó    € V ^8„  d   QhRRRR/# )é   ÚpathÚstrÚreturnÚNone© )Úformats   "ÚXC:\Users\johnn\AppData\Local\hermes\hermes-agent\hermes_cli\dashboard_auth\token_auth.pyÚ__annotate__r      s   € ÷  ñ  ˜sð   tñ  ó    c                ó†   € \         ;_uu_ 4        \        P                  V 4       RRR4       R#   + '       g   i     R# ; i)zZMark ``path`` (exact match) as token-authable. Idempotent; does NOT make the route public.N)Ú_lockr   Úadd©r   s   &r   Úregister_token_router"      s!   € ç	ŽÜ×Ñ˜$Ô÷ 
��Šús	   �/¯A 	c               ó    € V ^8„  d   QhRRRR/# )r   r   r   r   Úboolr   )r   s   "r   r   r   %   s   € ÷ %ñ %˜ð % ñ %r   c                ón   € \         ;_uu_ 4        V \        9   uuRRR4       #   + '       g   i     R# ; i)z@True if ``path`` was registered as token-authable (exact match).N)r   r   r!   s   &r   Úis_token_router&   %   s   € ç	ŽØ”}Ñ$÷ 
��‹ús   �	#£4	c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   +   s   € ÷ ñ ˜Dñ r   c                 ó„   € \         ;_uu_ 4        \        P                  4        RRR4       R#   + '       g   i     R# ; i)z,Test-only: drop all registered token routes.N)r   r   Úclearr   r   r   Úclear_token_routesr*   +   s   € ç	ŽÜ×ÑÔ÷ 
��Šús   �.®?	c               ó    € V ^8„  d   QhRRRR/# )r   Úrequestr   r   z.tuple[Optional[TokenPrincipal], Optional[str]]r   )r   s   "r   r   r   1   s   € ÷ ñ  ð Ð,Zñ r   c                ó’  € \        V 4      pV'       g   R# Rp\        4        F   p VP                  VR7      pTf   K  TR3u # 	  RV3#   \         d=   p\        P                  RTP                  T4       Tf   TP                  p Rp?Kj  Rp?i\         d-   p\        P                  RTP                  T4        Rp?KŸ  Rp?ii ; i)a  Try every token provider against the request's bearer token. Returns ``(principal, None)``
on success; ``(None, None)`` for no token or no recogniser (401); ``(None, name)`` when no
provider accepted it AND at least one was unreachable (caller surfaces 503). Never raises.N)Útokenz?dashboard-auth: token provider %r unreachable during verify: %sz:dashboard-auth: token provider %r raised during verify: %s)NN)Úextract_bearer_tokenr
   Úverify_tokenr   Ú_logÚwarningÚnameÚ	Exception)r,   r.   ÚunreachableÚproviderÚ	principalÚes   &     r   Úauthenticate_tokenr9   1   sÀ   € ô ! Ó)€EßØÐØ!%€KÜ(Ö*ˆð	Ø ×-Ñ-°EÐ-Ó:ˆIð Ô Ø˜d�?Ò"ñ +ð �ÐÐøô ô 	Ü�L‰LÐZØ!Ÿ™¨ô+àÒ"Ø&Ÿm™m�ÝûÜô 	Ü�L‰LÐUØ!Ÿ™¨ô+åûð	ús)   ¦A
Á
CÁ1BÂCÂCÂ!CÃCc               ó$   € V ^8„  d   QhRRRRRR/# )r   r,   r   Ú	call_nextz(Callable[[Request], Awaitable[Response]]r   r	   r   )r   s   "r   r   r   K   s)   € ÷ añ aØðaØ!IðaØNVñar   c           	   ƒ  óæ  "  € V P                   P                  p\        V4      '       g   V! V 4      G Rj  x€L
 # \        V 4      w  r4Ve2   W0P                  n        RV P                  n        V! V 4      G Rj  x€L
 # V'       d3   \        \        P                  VRV\        V 4      R7       \        V4      # \        \        P                  RV\        V 4      R7       \        RRR	R
/RR7      #  L· Lw5i)z}Pass-through for unregistered paths; for a token route, valid token -> attach principal +
flag, unreachable -> 503, else 401.NTÚprovider_unreachable)r6   Úreasonr   ÚipÚno_provider_recognises_token)r>   r   r?   ÚerrorÚunauthenticatedÚdetailÚUnauthorizedi‘  )Ústatus_code)Úurlr   r&   r9   ÚstateÚtoken_principalÚtoken_authenticatedr   r   ÚTOKEN_AUTH_FAILUREÚ
_client_ipr   r   )r,   r;   r   r7   r5   s   &&   r   Útoken_auth_middlewarerL   K   sÙ   é € ð �;‰;×Ñ€DÜ˜$×ÒÙ˜wÓ'×'Ð'Ü/°Ó8Ñ€IØÒØ(1�‰Ô%Ø,0ˆ�‰Ô)Ù˜wÓ'×'Ð'ßÜÜ×)Ñ)°KÐH^Øœ* WÓ-õ	/ô $ KÓ0Ð0äÜ×%Ñ%Ð.LÐSWÜ�gÓõ ô ˜Ð"3°X¸~ÐNÐ\_Ô`Ð`ñ (ñ
 (ùs)   ‚3C1µC-¶AC1Á7C/Á8C1ÂA*C1Ã/C1)+Ú__conditional_annotations__Ú__doc__Ú
__future__r   ÚloggingÚ	threadingÚtypingr   r   r   r   Úfastapir   Úfastapi.responsesr   r	   Úhermes_cli.dashboard_authr
   Úhermes_cli.dashboard_auth.auditr   r   Úhermes_cli.dashboard_auth.baser   r   Ú'hermes_cli.dashboard_auth.request_utilsr   rK   r   r/   r   Ú	getLoggerÚ__name__r1   Úsetr   Ú__annotations__ÚLockr   r"   r&   r*   r9   rL   )rM   s   @r   Ú<module>r^      s{   øðôõ #ã Û ß 7Ó 7å ß 4å :ß Aß H÷[ñ [ð ×Ò˜Ó"€á›%€ˆxÓ Ø�ŠÓ€õ õ%õõ÷4ar   