Ë
    ¼vëjV  ã                   óž   — d Z ddlZddlZddlmZmZ ddlmZmZ  ej                  d«      Z
dZdZdZd	ed
edee   fd„Z G d„ d«      Zg d¢Zy)ap  Who may call a GalaxiQ product's API: a signed-in user of the platform, or one of our own services.

A user arrives with the platform's JWT (the app sends it on every call); a service (the Node backend, another
product) arrives with the shared service key. Anyone else gets 401. Health and bootstrap stay open, and a product
may name more open paths (a chat widget visitors use, an OAuth callback).

    door = Door(jwt_key=settings.JWT_KEY, service_key=settings.GALAXIQ_SERVICE_KEY)
    app = FastAPI(dependencies=[Depends(door)])          # every route, every router

    caller = door.caller_of(request)    # {"kind": "user", "user_id", "email"} | {"kind": "service"} | None

No postponed annotations here: FastAPI resolves a dependency's parameter types from the callable's globals, and a
Door instance has none, so `request: Request` must be a real annotation, not a string.
é    N)ÚIterableÚOptional)ÚHTTPExceptionÚRequestzgalaxiq.authzx-galaxiq-service-key)z/healthz
/bootstrapzSign in required.ÚtokenÚjwt_keyÚreturnc                 óH  — ddl }	 |j                  | |dg¬«      }|j                  d«      xs |j                  d«      }|syt        |«      |j                  d«      d	œS # |j                  $ r3}t        j	                  dt        |«      j                  «       Y d}~yd}~ww xY w)
zb{user_id, email} from the platform's HS256 token, or None when it does not verify or names nobody.r   NÚHS256)Ú
algorithmszauth: token not verifiable (%s)ÚuserIdÚidÚemail)Úuser_idr   )	ÚjwtÚdecodeÚ
PyJWTErrorÚlogÚinfoÚtypeÚ__name__ÚgetÚstr)r   r   r   ÚpayloadÚexcr   s         ú\/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/galaxiq_utils/auth/__init__.pyÚactor_from_tokenr      sŽ   € ãðØ—*‘*˜U G¸¸	�*ÓBˆð �k‰k˜(Ó#Ò8 w§{¡{°4Ó'8€GÙØÜ˜7“|¨g¯k©k¸'Ó.BÑCÐCøð �>‰>ò Ü�‰Ð2´D¸³I×4FÑ4FÔGÜûðús   †A ÁB!Á.)BÂB!c            
       ór   — e Zd Zdddeffdededee   dee   fd„Zded	efd
„Zde	d	e
e   fd„Zde	d	efd„Zy)ÚDoorÚ © r   Úservice_keyÚ
open_pathsÚkey_headersc                 óî   — |xs d| _         |xs d| _        t        d„ g t        ¢|¢­D «       «      | _        t        |«      | _        | j                   s#| j                  st        j                  d«       y y y )Nr    c              3   óF   K  — | ]  }|j                  d «      xs d –— Œ y­w)ú/N)Úrstrip)Ú.0Úps     r   ú	<genexpr>z Door.__init__.<locals>.<genexpr>0   s    è ø€ Ò#b¸Q A§H¡H¨S£MÒ$8°SÓ$8Ñ#bùs   ‚!zZauth: neither JWT_KEY nor the service key is set; every call but the open paths is refused)	r   r"   Ú	frozensetÚOPEN_BY_DEFAULTr#   Útupler$   r   Úerror)Úselfr   r"   r#   r$   s        r   Ú__init__zDoor.__init__,   sh   € à’} "ˆŒØ&Ò,¨"ˆÔÜ#Ñ#bÐBaÄOÐBaÐV`ÑBaÔ#bÓbˆŒÜ  Ó-ˆÔØ�|Š| D×$4Ò$4Ü�I‰IÐrÕsð %5ˆ|ó    Úpathr	   c                 óD   — |j                  d«      xs d| j                  v S )Nr'   )r(   r#   )r0   r3   s     r   Úis_openzDoor.is_open5   s   € Ø—‘˜CÓ Ò' C¨D¯O©OÐ;Ð;r2   Úrequestc                 óö  — | j                   D ]T  }|j                  j                  |d«      }|sŒ"| j                  sŒ/t	        j
                  || j                  «      sŒPddic S  | j                  rŠ|j                  j                  dd«      }|j                  d«      r!t        |dd  | j                  «      }|rddi|¥S |j                  j                  dd«      }|rt        || j                  «      }|rddi|¥S y )	Nr    ÚkindÚserviceÚauthorizationzBearer é   Úuserr   )
r$   Úheadersr   r"   ÚhmacÚcompare_digestr   Ú
startswithr   Úquery_params)r0   r6   ÚheaderÚkeyr   Úactors         r   Ú	caller_ofzDoor.caller_of8   sï   € Ø×&Ñ&ò 	+ˆFØ—/‘/×%Ñ% f¨bÓ1ˆCÚ�t×'Ó'¬D×,?Ñ,?ÀÀT×EUÑEUÕ,VØ 	Ð*Ò*ð	+ð �<Š<Ø—O‘O×'Ñ'¨¸Ó<ˆEØ×Ñ 	Ô*Ü(¨¨q¨r¨°D·L±LÓA�ÙØ" FÐ4¨eÐ4Ð4Ø×(Ñ(×,Ñ,¨W°bÓ9ˆEÙÜ(¨°·±Ó=�ÙØ" FÐ4¨eÐ4Ð4Ør2   c                 ó    — | j                  |j                  j                  «      rddiS | j                  |«      }|€t	        dt
        ¬«      ‚|S )z+The FastAPI dependency: the caller, or 401.r8   Úopeni‘  )Ústatus_codeÚdetail)r5   Úurlr3   rE   r   ÚREFUSED)r0   r6   Úcallers      r   Ú__call__zDoor.__call__J   sH   € à�<‰<˜Ÿ™×(Ñ(Ô)Ø˜FÐ#Ð#Ø—‘ Ó(ˆØˆ>Ü¨C¼Ô@Ð@Øˆr2   N)r   Ú
__module__Ú__qualname__ÚSERVICE_KEY_HEADERr   r   r1   Úboolr5   r   r   ÚdictrE   rM   r!   r2   r   r   r   +   s}   „ Ø&(¸RÐ]_Ø/AÐ.Cñt ð t°sð tÈXÐVYÉ]ð tØ& s™mótð<˜Cð < Dó <ð ð ¨X°d©^ó ð$ ð ¨Dô r2   r   )r   r   rP   r-   rK   )Ú__doc__r>   ÚloggingÚtypingr   r   Úfastapir   r   Ú	getLoggerr   rP   r-   rK   r   rR   r   r   Ú__all__r!   r2   r   ú<module>rY      so   ðñó Û ß %ç *à€g×Ñ˜Ó'€à,Ð Ø+€Ø
€ðD˜Cð D¨#ð D°(¸4±.ó D÷&ñ &òR [�r2   